sqlite3-ruby: cannot load such file -- sqlite3 (LoadError)

Can you help? I’m new to development on Ruby. I tried to use SQLite in my app ( require 'sqlite3' ) and :

main.rb:5:in `require': cannot load such file -- sqlite3 (LoadError)
        from main.rb:5:in `<main>'

Windows 10 x64 ruby 2.4.3p205 (2017-12-14 revision 61247) [x64-mingw32] SQLite version 3.22.0 2018-01-22 18:45:57

*** LOCAL GEMS ***

actioncable (5.1.4)
actionmailer (5.1.4)
actionpack (5.1.4)
actionview (5.1.4)
activejob (5.1.4)
activemodel (5.1.4)
activerecord (5.1.4)
activesupport (5.1.4)
arel (8.0.0)
axiom-types (0.1.1)
bigdecimal (default: 1.3.0)
builder (3.2.3)
bundler (1.16.1)
coercible (1.0.0)
concurrent-ruby (1.0.5)
crass (1.0.3)
descendants_tracker (0.0.4)
did_you_mean (1.1.0)
equalizer (0.0.11)
erubi (1.7.0)
faraday (0.14.0)
globalid (0.4.1)
i18n (0.9.3)
ice_nine (0.11.2)
inflecto (0.0.2)
io-console (default: 0.4.6)
json (default: 2.0.4)
loofah (2.1.1)
mail (2.7.0)
method_source (0.9.0)
mini_mime (1.0.0)
mini_portile2 (2.3.0)
minitest (5.10.1)
multipart-post (2.0.0)
net-telnet (0.1.1)
nio4r (2.2.0)
nokogiri (1.8.1 ruby x64-mingw32)
openssl (default: 2.0.5)
power_assert (0.4.1)
psych (default: 2.2.2)
rack (2.0.3)
rack-test (0.8.2)
rails (5.1.4)
rails-dom-testing (2.0.3)
rails-html-sanitizer (1.0.3)
railties (5.1.4)
rake (12.0.0)
rdoc (default: 5.0.0)
sprockets (3.7.1)
sprockets-rails (3.2.1)
sqlite3 (1.3.13)
telegram-bot-ruby (0.8.6.1)
test-unit (3.2.3)
thor (0.20.0)
thread_safe (0.3.6)
tzinfo (1.2.4)
virtus (1.0.5)
websocket-driver (0.6.5)
websocket-extensions (0.1.3)
xmlrpc (0.2.1)

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 43 (1 by maintainers)

Most upvoted comments

I’ve tried go to Gem file in your proyect and put following code: gem ‘sqlite3’, git: “https://github.com/larskanis/sqlite3-ruby”, branch: “add-gemspec”

now in your terminal: bundle install

I’m using rails 5.2.1 and ruby version 2.5.1

It should work for you if you using ruby v. 2.4.3!.

вы все идиоты

gem ‘sqlite3’, git: “https://github.com/larskanis/sqlite3-ruby”, branch: “add-gemspec”

worked for me. windows 10 ruby 2.5.3-1 rails 5.2.2

but without this line in Gemfile, bundler tried to use 1.4.0 version of sqlite3 gem, still fails.

did everything listed above, and after bundle install I’m getting ‘could not locate Gemfile’

I’m on windows 10 ruby 2.5.3p105 rails 5.2.3

Any insight would be most appreciated.

@total-anachronism , I got some good news for you, bud. I am running the same specs as you, windows 10 and everything.

I looked into this Japanese blogpost: https://qiita.com/shita_fontaine/items/aa3f762d7afa20c5d42a and man, I finally got it to work. Here’s how.

First when creating a new rails project, make sure to add --skip-bundle into the end. So, for example, if you are following getting started section on railsguides and wanna create a blog the command on your shell command should be:

$ rails new blog --skip-bundle

This will allow you to get a jump on the damn thing. If you let the bundler run in the end and then try to change the gemfile, bundler will stubbornly install 1.4.0 version of sqlite3, which will fail to compile every single time.

So once it generates the base for you and you have successfully skipped the bundler in the end, NOW change the line in the GemFile:

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

to (as @WilfredoAlarcon has shown)

# Use sqlite3 as the database for Active Record
gem 'sqlite3', git: "https://github.com/larskanis/sqlite3-ruby", branch: "add-gemspec"

then run on your shell

$ bundle install

You will see that bundler will say bundle complete!, install the desired 1.3.13 version of sqlite3 from the git repo and when you run rails server, and breathe in relief that you will be able to access the damn server you worked so hard to get on to.

Let me know how it goes - because I did some wicked dragging and dropping of sqlite files and setting paths and whatever and it just kinda worked at one point from now on. If it works for you too - then great!

did everything listed above, and after bundle install I’m getting ‘could not locate Gemfile’

I’m on windows 10 ruby 2.5.3p105 rails 5.2.3

Any insight would be most appreciated.

@WilfredoAlarcon I am working with rails 5.0.6 and ruby 2.3.3 and this is the result of running bundle install after changing the Gemfile:

Fetching https://github.com/larskanis/sqlite3-ruby
Fetching gem metadata from https://rubygems.org/.............
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies........
......
......
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/bundler/gems/sqlite3-ruby-102750907917/ext/sqlite3
C:/RailsInstaller/Ruby2.3.3/bin/ruby.exe -r ./siteconf20190106-33920-1ph85e1.rb
extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Install SQLite3 from http://www.sqlite.org/ first.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.
.....
.....
Gem files will remain installed in
C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/bundler/gems/sqlite3-ruby-102750907917
for inspection.
Results logged to
C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/bundler/gems/extensions/x86-mingw32/2.3.0/sqlite3-ruby-102750907917/gem_make.out

An error occurred while installing sqlite3 (1.3.13.20180326210955), and Bundler
cannot continue.

In Gemfile:
  sqlite3

I’d appreciate some help!

I also got this error, anybody have suggestions for fixing it?