cannot load such file — sqlite3/sqlite3_native (Lo

2018-12-31 12:02发布

问题:

When I try to setup basic installation and initiation of server using Rails 4.0.0 on Ruby 2.0.0, I\'m facing the following error message.

/usr/local/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.7/lib/sqlite3.rb:6:in `require\': cannot load such file -- sqlite3/sqlite3_native (LoadError)
    from /usr/local/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.7/lib/sqlite3.rb:6:in `rescue in <top (required)>\'
    from /usr/local/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.7/lib/sqlite3.rb:2:in `<top (required)>\'
    from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require\'
    from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require\'
    from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each\'
    from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require\'
    from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each\'
    from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require\'
    from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler.rb:132:in `require\'
    from /home/penchal/new/site/config/application.rb:7:in `<top (required)>\'
    from /usr/local/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:76:in `require\'
    from /usr/local/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:76:in `block in <top (required)>\'
    from /usr/local/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `tap\'
    from /usr/local/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>\'
    from bin/rails:4:in `require\'
    from bin/rails:4:in `<main>\'

How can I avoid this error message and proceed further?

回答1:

Find your sqlite3 gemspec file. One example is /usr/local/share/gem/specifications/sqlite3-1.3.7.gemspec

Windows: C:\\Ruby21\\lib\\ruby\\gems\\2.1.0\\specifications.

You should adjust according with your Rubygem path and sqlite3 version. Edit the file above and look for the following line

s.require_paths=[\"lib\"]

change it to

s.require_paths= [\"lib/sqlite3_native\"]


回答2:

see:https://stackoverflow.com/a/39136421/6755206

fortunately, you don\'t have to switch to ruby 2.0
there is a solution to this issue, after endless trying...

https://github.com/hwding/sqlite3-ruby-win


Steps

Pre

  • gem uninstall sqlite3 --all

Source

  • Download the latest sqlite3-ruby, https://github.com/sparklemotion/sqlite3-ruby
  • unzip the package

Build

  • run command-line in the extracted dir
  • make sure you have your C compiler installed and added to PATH
  • gem install bundler
  • bundle install
  • rake native gem
  • you\'ll find a dir named \'pkg\' generated

Install

  • enter dir \'pkg\'
  • gem install --local sqlite3-xxx.gem (\'xxx\' is version code)

Check

  • irb
  • require \'sqlite3\'


回答3:

Since pull request #229 has been merged, sqlite3 can be installed per git: key. It\'s possible to use sqlite3 easily through this addition in your Gemfile :

gem \'sqlite3\', git: \"https://github.com/sparklemotion/sqlite3-ruby\"

This works on RubyInstaller-2.4 and newer. It automatically installs the required pacman package mingw-w64-x86_64-sqlite3 when you run bundler install.

There are some more hints for Rails on Windows in the RubyInstaller2 FAQ.



回答4:

No compiling of the sources or downloading pre-compiled libraries will solve this problem, believe me I tried everything, the problem lies somewhere else. This is how it works on windows:

bundle update sqlite3

You likely get another similar error after this one regarding nokogiri, fix it with the command:

bundle update nokogiri

Enjoy your Ruby App!



回答5:

Just edit Gemfile and add gem \'sqlite3\', platform: :ruby.



回答6:

Uninstalling and reinstalling the sqlite3 gem worked for me.

gem uninstall sqlite3

bundle


回答7:

This worked for me:

gem \'sqlite3\', git: \"https://github.com/larskanis/sqlite3-ruby\", branch: \"add-gemspec\"


回答8:

BEST OFFICIAL INSTALL

Im using rails 5.2.1p57, Windows 10 Just running following lines sloved the problem

gem uninstall sqlite3

and uninstall all installed versions. again execute following command

gem install sqlite3 --platform=ruby

You are now done. Let me know if problem persist.



回答9:

If the top answer doesn\'t work, a fix that I discovered is simply going to your Gemfile and adding the version number 1.3.11 (instead of 1.3.9) right after sqlite3. So the line in your Gemfile should now read:

# Use sqlite3 as the database for Active Record
gem \'sqlite3\',  \'1.3.11\'


回答10:

I had the same error when I upgrade my Ruby version to 2.5.X. I tracked with rails task --trace that the sqlite3 is not available to version 2.5, than I change my GemFile the gem \"sqlite3\" change to \"sqlite3-ruby\", after I uninstall the gem \"sqlite3\" and finally I run the bundle install.

I don\'t know what is the reason... I read that \"sqlite3\" is not available for ruby 2.5 yet, but I\'m not sure.



回答11:

To avoid this error, ensure that gem sqlite3 is added to your Gemfile. Then extract \"exe\"s and \"dll\"s from Sqlite download link to Ruby\'s bin folder. If problem still persists. Try this:

bundle update

gem uninstall sqlite3

Given a choice between multiple versions of sqlite3, choose last option \'All versions\'. Enter last number here

Select gem to uninstall:
1. sqlite3-1.3.13
2. sqlite3-1.3.13-x64-mingw32
3. All versions
>3 .
.
If you remove this gem, these dependencies will not be met.
Continue with Uninstall? [yN]
> y

gem install sqlite3 --platform=ruby

rails s

This should work.

Read through this link for more explanation if above works for you.



回答12:

This happened to me as well. It turned out that I had originally installed SQLite 1.3.10, but then I copied some gems from the Rails tutorial screencasts project and it listed SQLite 1.3.9. Then I got the same error you did. I changed it back to 1.3.10 and it worked.

(This is on Windows 7. I was running the screencast tutorial on Cloud9 IDE).



回答13:

This is the only solution worked for me, derived from this GitHub issue post:

  1. Get autoconf version of sqlite3 sources from https://www.sqlite.org/download.html.
  2. Start MSYS shell.
  3. In unpacked location for your sqlite3, configure static version only to avoid keeping DLL on PATH: ./configure --disable-shared.
  4. Build and install it: make install DESTDIR=/c/dev/ruby/tmp. You can change the directory.
  5. Open command prompt of windows and run gem uninstall sqlite3 --all to remove all existing sqlite3 gems.
  6. Again on command prompt of windows, build and install sqlite3 gem: gem install sqlite3 --platform=ruby -- --with-sqlite3-include=C:\\dev\\ruby\\tmp\\usr\\local\\include --with-sqlite3-lib=C:\\dev\\ruby\\tmp\\usr\\local\\lib. Those include and lib directories may be different, so check at first.

I am using Ruby version 2.5.1 and Rails version 5.2.0 on Windows 10.



回答14:

i found it! i saw this https://www.youtube.com/watch?v=lsrzvX0qzmA
i instaled: Rails version: 5.2.1 Ruby version: 2.5.3 (x64-mingw32) Sqlite version 1.3.13
and i have your problem... my solution:

  1. In your installing folder like C:\\Ruby25-x64\\lib\\ruby\\gems\\2.5.0\\gems\\
    you have folders: \"sqlite3-1.3.13\" \"sqlite3-1.3.13-x64-mingw32\"
  2. Find file
    C:\\Ruby25-x64\\lib\\ruby\\gems\\2.5.0\\gems\\sqlite3-1.3.13\\lib\\sqlite3\\sqlite3_native.so
  3. Copy it in C:\\Ruby25-x64\\lib\\ruby\\gems\\2.5.0\\gems\\sqlite3-1.3.13-x64-mingw32\\lib\\sqlite3\\2.5\\sqlite3_native.so (may be folders not exist - create and paste)


回答15:

gem uninstall sqlite3 --all
ridk exec pacman -S mingw-w64-x86_64-sqlite3
gem inst sqlite3 --platform ruby

This solved the problem to me.

Windows 10
Ruby 2.5.3
Rails 5.2.2