Ruby Ruby on Rails 5 Basics Creating an App Creating a Rails App

Erin Claudio
Erin Claudio
5,842 Points

sqlite3 error message not like the already stated issues.

Here is the error message in my command line - (Mac OS) after attempting to access localhost:3000:

Gem::LoadError (Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).): 

After a little research, I found that Homebrew already includes sqlite3 so I am confused as to why I am receiving this error.

Here is the info from the page I recieved

Gem::LoadError
Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
Extracted source (around line #176):
174
175
176
177
178
179

            require path_to_adapter
          rescue Gem::LoadError => e
            raise Gem::LoadError, "Specified '#{spec[:adapter]}' for database adapter, but the gem is not loaded. Add `gem '#{e.name}'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord)."
          rescue LoadError => e
            raise LoadError, "Could not load '#{path_to_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.", e.backtrace
          end

2 Answers

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,859 Points

You might have already installed SQLite with Homebrew, but you still need to install the gem to your Rails project (or at least, that's what I get from the error message). I would try what the error is suggesting and add a sqlite3 entry to your project's gem file. I haven't done anything in Rails for years now, so I can't help much after that 🙂.

Erin Claudio
Erin Claudio
5,842 Points

Thank you, Caleb, I will give it a try. This is very new ground for me !!

Jay McGavren
STAFF
Jay McGavren
Treehouse Teacher

Erin Claudio When you installed Rails, did you follow the directions in this video? Most importantly, did you install Rails using the command gem install rails --version 5.0.0? The code shown in the course won't (all) work correctly unless you're using Rails 5.0.0 specifically.

I'm betting that when you installed Rails, an error was shown in the terminal output when installing the sqlite3 gem. Try this:

  • gem uninstall rails
  • gem install rails --version 5.0.0

Copy the output from this second command, and paste it into a reply to this forum post. So that it's formatted properly, be sure to use 3 backtick (`) characters on the line before the output, and again on the line after. See the "Markdown Cheatsheet" link on the reply form for more info.

Erin Claudio
Erin Claudio
5,842 Points

Thank you for responding Jay!!

Yup Jay, I did (or at least I that is what I recall entering ) - I worked with a friend to find a solution and the version of sqlite3 had to be changed to '~> 1.3.6' in the gemfile.lock . I am now seeing the Rails version: 5.0.7.2 welcome page.

Perhaps I did not enter 5.0.0 and maybe just 5.0?

Jay McGavren
Jay McGavren
Treehouse Teacher

Erin Claudio I think the gem tool only tries to match the minor version (5.0 versus 5.1) and will move up a patch version (5.0.7 versus 5.0.0) if it's available, so that should be fine. You would only have had problems if it had installed Rails 5.1 or later (and even those would have been fairly minor).

Glad to hear you found a fix!