Ruby on Rails - “Add 'gem sqlite3'' to

2020-01-31 03:07发布

I'm a complete n00b on Rails with only beginner knowledge of Ruby. I plan on studying Ruby more before I really learn Rails, but I'm waayy too curious for my own good.

Anyway, I was following the 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." So 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.

If it helps, I got Ruby 2.0, Rails 4.0, sqlite3 1.3.7

I apologize if this was answered already somewhere else, but I couldn't find anything in the vast database that is stackoverflow. I would appreciate any patience that you are willing to provide.

Thank you very much! hewhocomes

11条回答
聊天终结者
2楼-- · 2020-01-31 03:18

worked for me sudo apt-get install libsqlite3-dev

查看更多
beautiful°
3楼-- · 2020-01-31 03:24

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

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2020-01-31 03:28

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!

查看更多
5楼-- · 2020-01-31 03:31

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)

查看更多
ら.Afraid
6楼-- · 2020-01-31 03:32
  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
查看更多
对你真心纯属浪费
7楼-- · 2020-01-31 03:33

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

查看更多
登录 后发表回答