如何启动已有Rails项目?GitHub项目运行sqlite3报错求助
Hey, I’ve run into this exact cannot load such file -- sqlite3/sqlite3_native (LoadError) issue on Windows before—let me walk you through the most reliable fixes that have worked for me and other Rails devs:
1. Lock sqlite3 to a version compatible with your Ruby/Rails setup
Windows has weird compatibility quirks with newer sqlite3 gem versions, especially with older Ruby (like 2.5.x) and Rails combinations. Here’s what to do:
- Open your project’s
Gemfileand replace the linegem 'sqlite3'with:
(This version is proven to play nice with Ruby 2.5.x on Windows)gem 'sqlite3', '~> 1.3.16' - Run this command to reinstall the gem with the correct version:
bundle install
2. Manually install the Windows-compatible sqlite3 gem
Sometimes the default gem installer skips the native extensions needed for Windows. Try this:
- First, download the precompiled Windows SQLite3 binaries (make sure it includes the
includeandlibfolders) and extract them toC:\sqlite. - Then run this command to install the gem with the correct path:
gem install sqlite3 --platform=ruby -- --with-sqlite3-dir="C:\sqlite"
- Finally, run
bundle installagain to link it to your project.
3. Verify your Ruby DevKit is set up correctly
Windows requires the Ruby DevKit to compile native gem extensions. Double-check it’s configured properly:
- Open a command prompt and navigate to your DevKit installation folder (usually something like
C:\RubyDevKit). - Run these commands to initialize and install the DevKit:
ruby dk.rb init ruby dk.rb install - Uninstall the broken sqlite3 gem first:
gem uninstall sqlite3 - Then run
bundle installagain to rebuild the gem with the correct environment.
4. Switch to a RubyInstaller build with bundled DevKit
If all else fails, uninstall your current Ruby version and reinstall using the RubyInstaller for Windows that includes the DevKit (look for the "Ruby+Devkit" package for Ruby 2.5.x). This sets up the native extension environment automatically, so you won’t have to mess with manual configurations. Once reinstalled, clone your project again (or run bundle install on your existing one) and try starting Rails with rails s again.
内容的提问来源于stack exchange,提问作者D. Matusik

