90

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?

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
  • what OS are you trying this on? – Saifis Jul 14 '13 at 22:07
  • Seems to be a windows problem. Solutions vary. See if this will do for you http://stackoverflow.com/a/6126062/2576857 . – Doodad Jul 14 '13 at 23:57
  • 1
    But it doesn't seem that he is using windows. Maybe [this article](http://ahmedemad.wordpress.com/2013/05/17/ruby-on-rails-install-run-error/) would be of help. – Althaf Hameez Jul 15 '13 at 00:26
  • 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. – Doodad Jul 15 '13 at 00:42
  • If Rails 4 and Ruby 2.1. - look [here](http://stackoverflow.com/questions/37365791/sqlite3-loaderror-incompatible-library-version/37457006#37457006) – discipleartem May 26 '16 at 09:54

20 Answers20

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"]
Rahil Wazir
  • 10,007
  • 11
  • 42
  • 64
Harish Gopalakrishnan
  • 1,504
  • 2
  • 11
  • 11
  • 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... –  Aug 23 '15 at 08:41
  • 1
    This worked for 1.3.9 but was not necessary for 1.3.11. I'm on Win7 x64. – Kidquick Mar 15 '16 at 15:05
  • sweet fix thank you. Not sure how you came up with this but it fixed my problem for ruby 2.1.0 – spartikus Jun 23 '16 at 15:36
  • 1
    Worked for me, but I don't want to get more new erros. – Sterling Diaz Sep 02 '16 at 17:35
  • 3
    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. – Sterling Diaz Sep 02 '16 at 17:36
  • 3
    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 http://guides.rubyonrails.org/getting_started.html – hello_earth Sep 25 '16 at 14:54
  • 2
    Two years? How about THREE years? – Warren P Oct 03 '16 at 17:38
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.

Lars Kanis
  • 886
  • 9
  • 7
19

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'
Community
  • 1
  • 1
hwding
  • 840
  • 10
  • 22
  • 1
    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). – aaossa Sep 19 '16 at 19:54
  • 1
    yes, after a lot of trying, this is the only way that worked.... other people (https://www.reddit.com/r/rails/comments/30s1cz/rails_on_windows_not_being_cooperative/) suggest moving to something like vagrant and skipping Windows+Rails altogether – hello_earth Sep 25 '16 at 14:50
  • 1
    I confirm this is the only solution working for windows 10; tried a couple of fixes but this is the only one working. – numediaweb Oct 06 '16 at 11:42
  • 1
    I have done according to the steps mentioned, but I don't see any folder created with the name `pkg`. – Yashu Mittal Sep 19 '18 at 10:53
  • 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. – MSC Jan 15 '19 at 22:51
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
Robert
  • 33,429
  • 8
  • 90
  • 94
Edson Momm
  • 160
  • 1
  • 6
  • 1
    OMG is this real :D Only this works for me, Windows 10 is terrible for RoR. Thanks a lot! – User 987 Jan 06 '19 at 03:17
  • Worked also for me. My problem started after an update from ruby 2.4 to ruby 2.6 on windows 10. – knut Jan 10 '19 at 21:57
  • This was the answer for me as well on Win10 Ruby 2.6 (x64). Thank you! – vercingortix Jan 18 '19 at 18:16
  • 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. – vercingortix Jan 30 '19 at 15:00
9

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

Ram
  • 991
  • 7
  • 8
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!

Norman Seßler
  • 154
  • 1
  • 3
4

Uninstalling and reinstalling the sqlite3 gem worked for me.

gem uninstall sqlite3

bundle
JackHasaKeyboard
  • 1,599
  • 1
  • 16
  • 29
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'
4

This worked for me:

gem 'sqlite3', git: "https://github.com/larskanis/sqlite3-ruby", branch: "add-gemspec"
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
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.

Pradeep Sapkota
  • 2,041
  • 1
  • 16
  • 30
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.

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.

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

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.

ismailarilik
  • 2,236
  • 2
  • 26
  • 37
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)
1

Updated

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

Ryan
  • 326
  • 2
  • 6
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
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/

Julian K
  • 1,877
  • 2
  • 19
  • 27
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.

ochi
  • 131
  • 1
  • 3
-1

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

Jetonii
  • 3
  • 2