Ruby on Rails - “Add 'gem sqlite3'' to your Gemfile”

前端 未结 11 1123
你的背包
你的背包 2020-12-05 13:51

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.

相关标签:
11条回答
  • 2020-12-05 14:27

    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.

    0 讨论(0)
  • 2020-12-05 14:31

    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.

    0 讨论(0)
  • 2020-12-05 14:34

    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

    0 讨论(0)
  • 2020-12-05 14:35

    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.

    0 讨论(0)
  • 2020-12-05 14:41

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

    0 讨论(0)
提交回复
热议问题