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:36

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"]
查看更多
余欢
3楼-- · 2018-12-31 12:37

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

查看更多
永恒的永恒
4楼-- · 2018-12-31 12:37

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'
查看更多
不流泪的眼
5楼-- · 2018-12-31 12:40

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.

查看更多
无色无味的生活
6楼-- · 2018-12-31 12:41
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
查看更多
浅入江南
7楼-- · 2018-12-31 12:42

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.

查看更多
登录 后发表回答