cannot load such file — sqlite3/sqlite3_native (Lo

2018-12-31 12:00发布

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?

15条回答
后来的你喜欢了谁
2楼-- · 2018-12-31 12:26

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.

查看更多
旧时光的记忆
3楼-- · 2018-12-31 12:33

Uninstalling and reinstalling the sqlite3 gem worked for me.

gem uninstall sqlite3

bundle
查看更多
裙下三千臣
4楼-- · 2018-12-31 12:34

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.

查看更多
妖精总统
5楼-- · 2018-12-31 12:35

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!

查看更多
高级女魔头
6楼-- · 2018-12-31 12:35

This worked for me:

gem 'sqlite3', git: "https://github.com/larskanis/sqlite3-ruby", branch: "add-gemspec"
查看更多
君临天下
7楼-- · 2018-12-31 12:35

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.

查看更多
登录 后发表回答