35

I was following the Rails tutorial, but I got stuck when it said to type rails server in the blog directory. It states

Specified 'sqlite3' for database adapter, but the gem is not loaded. Add gem 'sqlite3' to your Gemfile.

I quit the server, installed sqlite3, reinstated the server, only to get this message again. sqlite3 doesn't show up when I do gem list, but I do see the folder in my Root Ruby directory.

How can I fix this error?

I'm using Ruby 2.0, Rails 4.0, sqlite3 1.3.7.

ggorlen
  • 44,755
  • 7
  • 76
  • 106
hewhocomes
  • 441
  • 1
  • 4
  • 9
  • Could you please extend your question which operation system do you use? I guess, you use Win7, there is a little trick with sqlite3... – Zoltan Jun 30 '13 at 01:15

11 Answers11

30

In my case, this error "Specified 'sqlite3' for database adapter, but the gem is not loaded. Add gem 'sqlite3' to your Gemfile." message showed up, when I ran rails server right after I generated a fresh rails app. It was with Rails version 4.1.16 (Ruby version 2.3.1)

gem 'sqlite3', '~> 1.3.0'

This line in Gemfile removed the error message. I think new sqlite gem (version 1.4) has a conflict with old rails (version 4.1) but I didn't see any related issue on their Github repository. I'm adding this answer here because it might help anybody experiencing the same situation I'm in.

kangkyu
  • 5,252
  • 3
  • 34
  • 36
25

I had this error appear with the same version of Ruby / Rails / SQLite that you specified in your question even after confirming that my gemfile has gem 'sqlite3'. I don't know what OS you have (which is why you were down-voted probably) but I am using Windows 7 x64.

In order to get the gem to be installed in my Rails application, I needed to edit the Gemfile.lock file to replace sqlite3 (1.3.7-x86-mingw32) with sqlite3 (1.3.7)

Then, after running bundle install I finally see in the output

Using sqlite3 (1.3.7)

Upon running rails server, I (finally) see the "Welcome aboard" page.

Paul
  • 617
  • 6
  • 14
  • You can try to use `gem list sqlite3` and if you see more version from sqlite3 and for example would like to delete `sqlite3-mingw32` or simiar just use `gem uninstall sqlite3-mingw32`. You don't have to edit Gemfile.lock... but you have to repeat this steps if you use `bundle update` in your project. – Zoltan Jun 30 '13 at 01:13
  • When I run `gem list sqlite3` I see only one item: `sqlite3 (1.3.7)`. I originally ran `gem list` and that is when I saw the mismatch in versions. If you can help me understand why that would be an issue that would be appreciated - I am still a bit new at this. Generally speaking, it looks like 64bit Ruby on Windows has some issues; for example you can't use Capybara DSL inside of rspec with it because [nokogiri doesn't support 64bit Ruby on Windows yet](https://github.com/sparklemotion/nokogiri/issues/864). (I am trying to get it all running as part of the (excellent) Rails tutorial.) – Paul Jul 01 '13 at 10:36
  • Paul, I totally understand your feeling... I've begun to learn Ruby on Windows as well, but I realized life is much more nicer with using a virtual machine and an ubuntu linux in it... Just drop me a private message if you need help. – Zoltan Jul 04 '13 at 01:08
  • I fixed the issue by doing this: edit Gemfile and change gem 'sqlite3', '~> 1.4' to gem 'sqlite3', '~> 1.4.2' and save, then run gem install sqlite3 -v '1.4.2', then run bundle update – JJ_Coder4Hire Mar 20 '20 at 05:31
17

I'd the same problem on a x64 win 7.

Solution (for me):

1) Install sqlite3

gem install sqlite3

2) Check the installed version

gem list sqlite3

It gives me: sqlite3 (1.3.8 x64-mingw32)

3) Modify the Gemfile.lock

I change "sqlite3 (1.3.8-x86-mingw32)" by "sqlite3 (1.3.8-x64-mingw32)

It works :) Note that you to need add a "-" between the version number and the x64 in the Gemfile.lock

Xmass

ᗩИᎠЯƎᗩ
  • 2,122
  • 5
  • 29
  • 41
Xmass
  • 171
  • 1
  • 2
13

Another potential solution found on this post

I already had sqlite installed, but apparently since Feb 4, 2019 there's an issue with the sqlite3 v1.4.0 gem.

In the meantime, you can fall back to v1.3.6 by adding that version to the “sqlite3” line in your Gemfile, like so:

gem 'sqlite3', '~> 1.3.6'

Hope this saves someone the time!

Mohamed Adel
  • 1,980
  • 17
  • 23
gwalshington
  • 1,418
  • 2
  • 30
  • 60
6

Problem Solved!

Turns out, it was several different problems:

  1. I previously overlooked that sqlite3 needed to be installed in order to run, as stated in rubyonrails.org's Getting Started guide. The guide gave me a link to sqlite.com, from which I needed to download the command shell and the dll, both are under "Precompiled Binaries for Windows". More on this below.

  2. The gem install gave me an error that stated it couldn't download anything from rubygems.org. Turns out, there was a new version of rubygems I wasn't aware of. Fixed with gem update --system.

  3. I tried gem install sqlite3 --platform=ruby, but to no avail. It couldn't build a native extension and couldn't find sqlite3.h.

  4. I had asked my question also on ruby-forums. http://www.ruby-forum.com/topic/4415126 Here, a Joel Pearson(virtuoso) provided the missing files that I needed via attachment, since these files are not provided in sqlite.com. I followed his instructions, including putting the shell and dll files in my root Ruby's bin directory...and it worked!

So basically, I was able to install sqlite3 without modifying any Gemfile or Gemfile.lock. My gem list shows sqlite3 (1.3.7) and Rails's Welcome screen now appears as the Getting Started guide shows! I use Windows 7-64 bit, Ruby 2.0, Rails 4.0 and I now got sqlite3 1.3.7.

Thank you very much everyone for giving this n00b advice and direction. I find that having explored the Gemfiles as well as my root Ruby directory, I understand how Ruby and Rails are fit into my computer better.

As a beginner, I would recommend being able to download the sqlite3 files and folders needed to install it on Windows both on rubyonrails.org's Getting Started guide and in sqlite.com.

Thanks again! hewhocomes

hewhocomes
  • 441
  • 1
  • 4
  • 9
  • I'm curious to know if you progressed further in the tutorial without any other issues. Did you have a problem getting rspec working? – Paul Jul 15 '13 at 09:50
  • I'd like to add that I got it working using only the '--with-opt-dir=' parameter, using the files provided by Joel. Thanks! :-) – nicohvi Aug 01 '13 at 18:36
5
  1. Don't make another database global and then make sqlite3 specific to an environment on your gem file.
  2. Use a previous gem.
  3. Make sure you run bundle install, then bundle update, and lastly bundle install.

Your Gemfile might include entries like this:

group :development, :production do
  gem 'pg', '0.15.1'
end

group :test do
  gem 'sqlite3', '1.3.6'
end
smholloway
  • 589
  • 7
  • 14
Lesly Revenge
  • 894
  • 10
  • 16
4

Run the commands in the following order

sudo apt-get install libsqlite3-dev

sudo gem install sqlite3-ruby

gem list

After this command you will see the following versions of sqlite

sqlite3 (1.3.12)

sqlite3-ruby (1.3.3)

Syed_Shahiq
  • 566
  • 6
  • 13
3

For me it helped to put version after gem 'sqlite3' in gemfile, so it became gem 'sqlite3', '1.3.7'. Previously I tried to compile sqlite3, updated gem, etc... Rails wasn't able to "accept" it still, so finally defining the version helped.

Kris Avi
  • 61
  • 1
  • 7
  • Perhaps you have multiple versions of sqlite3? Are you on Windows as well? I'm just curious. Everything worked without me having to redefine the gemfile. This is something that I would need to remember if for some reason Rails complains about it again. – hewhocomes Jul 20 '13 at 12:19
  • That worked for me, too. I only have a single version of the sqlite3 gem but Rails (same config as OP) didn't see it until I included the version. Thanks! – Clay Jul 25 '13 at 00:05
2

worked for me sudo apt-get install libsqlite3-dev

Eduardo Herrera
  • 79
  • 1
  • 15
1

One small, but important side note for anyone running into this error. Prior to version 1.4, Bundler could not understand 64 bit gems on Windows (https://github.com/bundler/bundler/issues/2658) which explains why the 32bit versions were showing up in Gemfile.lock.

Manually changing:

"sqlite3 (1.3.8-x86-mingw32" to "sqlite3 (1.3.8-x64-mingw32)"

works if you're using an older version of bundler. Bundler should be able to automatically figure things out now if you upgrade (1.5.2 currently works for me).

WebDev
  • 1,097
  • 8
  • 6
0

Just add this line to your Gemfile, which is located in the root folder of your application

  gem 'sqlite3'
maximus ツ
  • 7,949
  • 3
  • 25
  • 54
  • 1
    Thanks, maximus. I tried putting in gem sqlite3 as a new line, continued the lines with # gem sqlite3 and even # Use sqlite3# gem sqlite3 and #sqlite3, group :deployment. Although I can only guess at what all that means...none of them worked. Once this is figured out, would I need to make these kind of changes for every app I make? Thank you! – hewhocomes Jun 27 '13 at 20:23
  • I forgot to mention: I found the gem listed in Gemfile.lock – hewhocomes Jun 27 '13 at 20:41
  • Update: I just saw this in Gemfile: "# Use sqlite3 as the database for Active Record gem 'sqlite3'" – hewhocomes Jun 27 '13 at 20:45