cannot load such file -- sqlite3/sqlite3_native (LoadError) on ruby on rails

Ruby on-RailsSqlite

Ruby on-Rails Problem Overview


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?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

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"]

Solution 2 - Ruby on-Rails

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.

Solution 3 - Ruby on-Rails

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

###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'

Solution 4 - Ruby on-Rails

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

Solution 5 - Ruby on-Rails

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

Solution 6 - Ruby on-Rails

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!

Solution 7 - Ruby on-Rails

Uninstalling and reinstalling the sqlite3 gem worked for me.

gem uninstall sqlite3

bundle

Solution 8 - Ruby on-Rails

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'

Solution 9 - Ruby on-Rails

This worked for me:

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

Solution 10 - Ruby on-Rails

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.

Solution 11 - Ruby on-Rails

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.

Solution 12 - Ruby on-Rails

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.

Solution 13 - Ruby on-Rails

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).

Solution 14 - Ruby on-Rails

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.

Solution 15 - Ruby on-Rails

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<br> 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)

Solution 16 - Ruby on-Rails

Updated

Adding the below to the Gemfile fixed for me: gem 'sqlite3', '1.4.0', platforms: :ruby

Solution 17 - Ruby on-Rails

Change your sqlite3 gem in the Gemfile for this:

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

Then run:

bundle install

Solution 18 - Ruby on-Rails

For OSX users, this can result from using a ruby manager (e.g. rvm).

If you edit your ~/.bash_profile and add this:

[[ "$APP" = *"/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/"* ]] && {
  echo Xcode detected
  rvm use system
}

You can work around the issue. Restart Xcode before attempting to build again.

The actual issue is tracked here: https://openradar.appspot.com/28726736).

Full credit goes to: https://egeek.me/2018/04/14/ipa-export-error-in-xcode-and-ruby/

Solution 19 - Ruby on-Rails

I had the same probe but its quite simple,

gem uninstall sqlite3 --all

then run

gem install sqlite3

everything should work well from there.

Solution 20 - Ruby on-Rails

I tried: sudo apt-get install sqlite3 Then I tried: gem install sqlite3 And it worked

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPenchala Reddy AudireddyView Question on Stackoverflow
Solution 1 - Ruby on-RailsHarish GopalakrishnanView Answer on Stackoverflow
Solution 2 - Ruby on-RailsLars KanisView Answer on Stackoverflow
Solution 3 - Ruby on-RailshwdingView Answer on Stackoverflow
Solution 4 - Ruby on-RailsEdson MommView Answer on Stackoverflow
Solution 5 - Ruby on-RailsRamView Answer on Stackoverflow
Solution 6 - Ruby on-RailsNorman SeßlerView Answer on Stackoverflow
Solution 7 - Ruby on-RailsJackHasaKeyboardView Answer on Stackoverflow
Solution 8 - Ruby on-RailsAndrew BrittonView Answer on Stackoverflow
Solution 9 - Ruby on-RailsBolan OluwaView Answer on Stackoverflow
Solution 10 - Ruby on-RailsPradeep SapkotaView Answer on Stackoverflow
Solution 11 - Ruby on-RailsAdrian HiguitaView Answer on Stackoverflow
Solution 12 - Ruby on-RailsSaurabh BorseView Answer on Stackoverflow
Solution 13 - Ruby on-RailsPaul MaciasView Answer on Stackoverflow
Solution 14 - Ruby on-RailsismailarilikView Answer on Stackoverflow
Solution 15 - Ruby on-RailsRoman DergunovView Answer on Stackoverflow
Solution 16 - Ruby on-RailsRyanView Answer on Stackoverflow
Solution 17 - Ruby on-RailsNicolás NisoriaView Answer on Stackoverflow
Solution 18 - Ruby on-RailsJulian KView Answer on Stackoverflow
Solution 19 - Ruby on-RailsochiView Answer on Stackoverflow
Solution 20 - Ruby on-RailsJetoniiView Answer on Stackoverflow