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

20

92

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?

Mountebank answered 14/7, 2013 at 21:22 Comment(5)
what OS are you trying this on?Validate
Seems to be a windows problem. Solutions vary. See if this will do for you https://mcmap.net/q/242214/-error-quot-no-such-file-to-load-quot-sqlite3-sqlite3_native-loaderror .Incapacitate
But it doesn't seem that he is using windows. Maybe this article would be of help.Deach
Oh yeah, /usr/local/etc, saw that now, my bad. From what I found, most people having this problem was because of sqlite exe and dll not in PATH variable, but that only happened to windows users. I think that article you provided should hit the nail on the head, but let's wait and see.Incapacitate
If Rails 4 and Ruby 2.1. - look hereSaprophagous
C
121

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"]
Congenital answered 20/7, 2013 at 12:45 Comment(7)
This is a fantastic error to a problem which shouldn't exist in the first place, given the number of Rails users on Windows. I would love to know why exactly this works though...Ricciardi
This worked for 1.3.9 but was not necessary for 1.3.11. I'm on Win7 x64.Celloidin
sweet fix thank you. Not sure how you came up with this but it fixed my problem for ruby 2.1.0Apus
Worked for me, but I don't want to get more new erros.Sex
It already presented and error: Could not load 'active_record/connection_adapters/sqlite3_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.Sex
the above error with the adapter doesn't seem to be solvable, doing what hwding suggests below first would save me quite some time - again though, maybe they'll fix that in the next releases, or fixed that in stacked packages like RailsInstaller (ruby2.3.1 with devkit(mingw with build tools), rails5.0.0.1) p.s. it's unbelievable that this problem still persists, after 2 years - given that sqlite is used by default in the skeleton default application, and is the way to go in guides.rubyonrails.org/getting_started.htmlWorthington
Two years? How about THREE years?Hardesty
M
21

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.

Mapes answered 9/4, 2018 at 15:53 Comment(4)
This answer is helpful for the new ruby installers ruby version ruby 2.5.1p57 (2018-03-29 revision 63029) and rails version Rails 5.2.1Renn
The PR has been merged in the meanwhile. I updated my answer accordingly.Mapes
To get around SSL issues I used: gem 'sqlite3', git: "git://github.com/sparklemotion/sqlite3-ruby.git"Latricialatrina
probably no longer need the git repoHaggadah
L
20

see:https://mcmap.net/q/242216/-windows-ruby-rails-install-cannot-load-such-file-sqlite3-sqlite3_native-windows

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'
Leboeuf answered 4/9, 2016 at 5:19 Comment(5)
Thanks @hwding. This works perfectly! In my case, Windows user, it seems like two sqlite3 versions (32 and 64 bits) were compiled in 'pkg', but I just installed the 64bits one (my case).Chemosmosis
yes, after a lot of trying, this is the only way that worked.... other people (reddit.com/r/rails/comments/30s1cz/…) suggest moving to something like vagrant and skipping Windows+Rails altogetherWorthington
I confirm this is the only solution working for windows 10; tried a couple of fixes but this is the only one working.Vannavannatta
I have done according to the steps mentioned, but I don't see any folder created with the name pkg.Absinthism
Worked for me up to you'll find a dir named 'pkg' generated as I didn't see such a directory anywhere. @Edson Momm's solution below worked for me.Hodson
I
16
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
Illona answered 20/12, 2018 at 15:36 Comment(4)
OMG is this real :D Only this works for me, Windows 10 is terrible for RoR. Thanks a lot!Townsville
Worked also for me. My problem started after an update from ruby 2.4 to ruby 2.6 on windows 10.Eyra
This was the answer for me as well on Win10 Ruby 2.6 (x64). Thank you!Heterothallic
I actually had to do this a few times. Seems that any time I would do a bundle install in order to install a new gem, I would run into this issue again and would need to repeat the above steps.Heterothallic
Z
9

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

Zeitgeist answered 9/8, 2018 at 4:33 Comment(0)
B
6

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!

Ber answered 30/6, 2017 at 13:41 Comment(0)
I
4

Uninstalling and reinstalling the sqlite3 gem worked for me.

gem uninstall sqlite3

bundle
Isomerize answered 15/9, 2015 at 17:37 Comment(0)
R
4

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'
Reynaldoreynard answered 14/4, 2016 at 1:29 Comment(0)
E
4

This worked for me:

gem 'sqlite3', git: "https://github.com/larskanis/sqlite3-ruby", branch: "add-gemspec"
Emilemile answered 12/9, 2018 at 0:5 Comment(0)
G
4

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.

Geostatic answered 18/9, 2018 at 5:28 Comment(0)
A
2

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.

Arran answered 11/8, 2018 at 4:19 Comment(0)
D
2

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.

Dingle answered 16/10, 2018 at 9:18 Comment(0)
L
1

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

Leonorleonora answered 14/5, 2015 at 6:16 Comment(0)
C
1

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.

Callimachus answered 13/4, 2018 at 16:30 Comment(1)
and gemspec file in the Gem's source folderMeacham
B
1

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)
Benedetto answered 27/10, 2018 at 21:51 Comment(0)
R
1

Updated

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

Revenant answered 28/1, 2019 at 4:19 Comment(0)
P
1

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
Pogue answered 23/8, 2019 at 19:4 Comment(0)
T
0

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/

Tiein answered 8/2, 2019 at 19:37 Comment(0)
Y
0

I had the same probe but its quite simple,

gem uninstall sqlite3 --all

then run

gem install sqlite3

everything should work well from there.

Yb answered 16/4, 2021 at 11:22 Comment(0)
V
-1

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

Vardhamana answered 13/8, 2021 at 5:43 Comment(3)
gem install sqlite3 has already been mentioned in other answers.Sideling
I tried gem install sqlite3 and it didn't work, while "sudo apt-get install sqlite3" worked.Vardhamana
Your comment says the opposite of what your answer says.Sideling

© 2022 - 2024 — McMap. All rights reserved.