Ruby on Rails - “将'gem sqlite3'' 添加到您的 Gemfile”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17350837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:14:56  来源:igfitidea点击:

Ruby on Rails - "Add 'gem sqlite3'' to your Gemfile"

ruby-on-railsrubysqliteruby-on-rails-4ruby-2.0

提问by hewhocomes

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.

我是一个完整的 Rails n00b,只有 Ruby 的初学者知识。我计划在我真正学习 Rails 之前更多地学习 Ruby,但我对自己的利益太好奇了。

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.

无论如何,我一直在学习教程,但是当它说在博客目录中键入“rails server”时我被卡住了。它指出,“为数据库适配器指定了‘sqlite3’,但未加载 gem。添加gem 'sqlite3'到您的 Gemfile。” 所以我退出了服务器,安装了 sqlite3,恢复了服务器......只是再次收到此消息。当我执行“gem list”时,sqlite3 没有出现,但我确实在我的 Root Ruby 目录中看到了该文件夹。

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

如果有帮助,我有 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.

如果已经在其他地方回答了这个问题,我深表歉意,但我在庞大的 stackoverflow 数据库中找不到任何内容。如果您愿意提供耐心,我将不胜感激。

Thank you very much! hewhocomes

非常感谢!他来了

采纳答案by hewhocomes

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/4415126Here, 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!

  1. 我之前忽略了需要安装 sqlite3 才能运行,如 ruby​​onrails.org 的入门指南中所述。该指南给了我一个指向 sqlite.com 的链接,我需要从中下载命令外壳和 dll,两者都在“Windows 预编译二进制文件”下。更多关于这个下面。

  2. gem 安装给了我一个错误,指出它无法从 ruby​​gems.org 下载任何东西。事实证明,有一个我不知道的新版本的 ruby​​gems。修复了 gem update --system。

  3. 我试过 gem install sqlite3 --platform=ruby,但无济于事。它无法构建本机扩展,也无法找到 sqlite3.h。

  4. 我也在 ruby​​-forums 上问过我的问题。 http://www.ruby-forum.com/topic/4415126在这里,Joel Pearson(virtuoso)通过附件提供了我需要的丢失文件,因为 sqlite.com 中没有提供这些文件。我遵循了他的指示,包括将 shell 和 dll 文件放在我的 Ruby 根目录中的 bin 目录中……它奏效了!

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.

所以基本上,我能够在不修改任何 Gemfile 或 Gemfile.lock 的情况下安装 sqlite3。我的 gem 列表显示 sqlite3 (1.3.7) 并且 Rails 的欢迎屏幕现在出现在入门指南中!我使用 Windows 7-64 位、Ruby 2.0、Rails 4.0,现在我得到了 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.

非常感谢大家给这个 n00b 建议和方向。我发现在探索了 Gemfiles 以及我的 Ruby 根目录之后,我明白了 Ruby 和 Rails 如何更好地适应我的计算机。

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.

作为初学者,我建议能够在 ruby​​onrails.org 的入门指南和 sqlite.com 上下载在 Windows 上安装所需的 sqlite3 文件和文件夹。

Thanks again! hewhocomes

再次感谢!他来了

回答by Paul

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.

即使在确认我的 gemfile 具有gem 'sqlite3'. 我不知道你有什么操作系统(这就是你可能被否决的原因),但我使用的是 Windows 7 x64。

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

为了让 gem 安装在我的 Rails 应用程序中,我需要编辑Gemfile.lock文件以替换sqlite3 (1.3.7-x86-mingw32)sqlite3 (1.3.7)

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

然后,在运行 bundle install 后,我终于在输出中看到

Using sqlite3 (1.3.7)

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

在运行 rails 服务器时,我(终于)看到了“欢迎登机”页面。

回答by kangkyu

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 serverright after I generated a fresh rails app. It was with Rails version 4.1.16 (Ruby version 2.3.1)

就我而言,"Specified 'sqlite3' for database adapter, but the gem is not loaded. Add gem 'sqlite3' to your Gemfile."当我在rails server生成新的 Rails 应用程序后立即运行时,出现了此错误消息。它是 Rails 版本 4.1.16(Ruby 版本 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.

Gemfile 中的这一行删除了错误消息。我认为新的 sqlite gem(1.4 版)与旧的 Rails(4.1 版)有冲突,但我在他们的 Github 存储库中没有看到任何相关问题。我在这里添加这个答案是因为它可能会帮助遇到与我相同情况的任何人。

回答by Xmass

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

我在 x64 win 7 上遇到了同样的问题。

Solution (for me):

解决方案(对我来说):

1) Install sqlite3

1)安装sqlite3

gem install sqlite3

宝石安装sqlite3

2) Check the installed version

2)检查安装的版本

gem list sqlite3

宝石列表 sqlite3

It gives me: sqlite3 (1.3.8 x64-mingw32)

它给了我: sqlite3 (1.3.8 x64-mingw32)

3) Modify the Gemfile.lock

3)修改Gemfile.lock

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

我将“sqlite3(1.3.8-x86-mingw32)”更改为“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

它有效:) 请注意,您需要在 Gemfile.lock 中的版本号和 x64 之间添加“-”

Xmass

圣诞节

回答by gwalshington

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.

我已经安装了 sqlite,但显然自 2019 年 2 月 4 日起,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:

同时,您可以通过将该版本添加到 Gemfile 中的“sqlite3”行来回退到 v1.3.6,如下所示:

gem 'sqlite3', '~> 1.3.6'

Hope this saves someone the time!

希望这可以节省时间!

回答by Lesly Revenge

  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.
  1. 不要将另一个数据库设为全局,然后让 sqlite3 特定于您的 gem 文件中的环境。
  2. 使用以前的宝石。
  3. 确保你运行bundle install,然后bundle update,最后bundle install

Your Gemfilemight include entries like this:

Gemfile可能包含这样的条目:

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

group :test do
  gem 'sqlite3', '1.3.6'
end

回答by Kris Avi

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.

对我来说,它有助于将版本gem 'sqlite3'放在 gemfile 之后,所以它变成了gem 'sqlite3', '1.3.7'. 以前我尝试编译 sqlite3、更新的 gem 等...... Rails 仍然无法“接受”它,所以最终定义版本有帮助。

回答by Eduardo Herrera

worked for me sudo apt-get install libsqlite3-dev

对我来说有效 sudo apt-get install libsqlite3-dev

回答by Syed_Shahiq

Run the commands in the following order

按以下顺序运行命令

sudo apt-get install libsqlite3-dev

sudo apt-get install libsqlite3-dev

sudo gem install sqlite3-ruby

sudo gem install sqlite3-ruby

gem list

gem list

After this command you will see the following versions of sqlite

执行此命令后,您将看到以下版本的 sqlite

sqlite3 (1.3.12)

sqlite3 (1.3.12)

sqlite3-ruby (1.3.3)

sqlite3-ruby (1.3.3)

回答by Corlew Solutions

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.

对于遇到此错误的任何人来说,这是一个很小但很重要的旁注。在 1.4 版之前,Bundler 无法理解 Windows ( https://github.com/bundler/bundler/issues/2658)上的 64 位 gem,这解释了为什么 32 位版本出现在 Gemfile.lock 中。

Manually changing:

手动更改:

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

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

如果您使用的是旧版本的捆绑器,则可以使用。如果您升级,Bundler 现在应该能够自动解决问题(目前 1.5.2 对我有用)。