我该如何在安装Ruby on Rails时安装SQLite3?

3

我是一名编程新手,正在尝试在Windows 10上安装Ruby on Rails。

我已经尝试了多次运行gem install bundler,但总是出现SQLite3错误。

命令提示符表示要从http://www.sqlite.org/安装SQLite3,但我不知道在目录中放置它的位置。

我查看了mkmf.log,但我无法理解它告诉我的内容。

当我查看RailsInstaller的“bin”文件夹时,sqlite3.def、sqlite 3.dll、sqlite3应用程序和sqlite3_ruby(文件和批处理文件)均存在。

如果有人知道可能出错的原因以及如何修复它,我会非常感激帮助,这个问题在在线操作指南中从未发生过。

非常感谢

命令提示符消息:

An error occurred while installing sqlite3 (1.4.0), and Bundler cannot continue. Make sure that gem install sqlite3 -v '1.4.0' --source 'https://rubygems.org/' succeeds before bundling.

In Gemfile: sqlite3

C:\Sites\test_app>gem install sqlite3 -v 1.4.0 Temporarily enhancing PATH to include DevKit... Building native extensions. This could take a while... ERROR: Error installing sqlite3: ERROR: Failed to build gem native extension.

current directory: C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/sqlite3-1.4.0/ext/sqlite3

C:/RailsInstaller/Ruby2.3.3/bin/ruby.exe -r ./siteconf20190317-7152-n0tljg.rb extconf.rb checking for sqlite3.h... no sqlite3.h is missing. Install SQLite3 from http://www.sqlite.org/ first. * extconf.rb failed * Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.

Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=C:/RailsInstaller/Ruby2.3.3/bin/$(RUBY_BASE_NAME) --with-sqlcipher --without-sqlcipher --with-sqlite3-config --without-sqlite3-config --with-pkg-config --without-pkg-config --with-sqlcipher --without-sqlcipher --with-sqlite3-dir --without-sqlite3-dir --with-sqlite3-include --without-sqlite3-include=${sqlite3-dir}/include --with-sqlite3-lib --without-sqlite3-lib=${sqlite3-dir}/lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/extensions/x86-mingw32/2.3.0/sqlite3-1.4.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/sqlite3-1.4.0 for inspection. Results logged to C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/extensions/x86-mingw32/2.3.0/sqlite3-1.4.0/gem_make.ou


1
你真的需要最新版本的sqlite吗?我安装1.4版本时也遇到了问题,但是1.3.13版本对我来说没有问题。 - knut
感谢您的回答 - 它显示已经安装成功,但是当我创建一个新的Rails文件时,它仍然试图安装sqlite3 1.4.0而不是1.3.13,1.3.13在C:\Ruby25-x64\lib\ruby\gems\2.5.0\gems中,我需要将它移动到其他地方吗? - user11216582
3个回答

7
Rails 试图自动安装最新版本的 sqlite3 gem (1.4),但是该新版本目前与 Rails 不兼容。请使用以下方式指定可与 Rails 兼容的版本:
Gemfile:
gem 'sqlite3', '< 1.4'

请重新运行bundle install命令。

谢谢 - 就像 C:\Users\Owner>gem 'sqlite3', '< 1.4' 这样的字面意思是什么?我是新手,不确定无效命令会是什么样子。当我输入这个或类似的东西时,它会显示“系统找不到指定的文件”。我还尝试了 C:\Users\Owner>gem install sqlite3 1.3.13,但似乎在“缺少函数dlopen”处失败了。 - user11216582
@SJM1 不是的。在你的Rails应用程序目录中,有一个名为Gemfile的文件。打开该文件并将当前为gem 'sqlite3'的行更新为上面指定的版本。然后保存该文件,并在与Gemfile相同的目录中在命令行上运行bundle install - Unixmonkey
我用记事本打开了它(有很多名为Gemfile的文件,只有一个带有那行代码),并进行了更新,但我不确定是否正确运行了bundle install文件。当你说在与Gemfile相同的目录中时,你是指文件夹还是命令提示符?它仍然在尝试安装1.40版本。 - user11216582
@SJM1 在命令提示符中调用 bundle install ,例如 cd c:\path\to\your\rails\app && bundle install - Unixmonkey
嗯,它找不到,我可能需要找一个人能够与我亲自一起检查。无论如何,感谢@Unixmonkey提供的所有帮助。 - user11216582
非常感谢。我已经为此苦苦挣扎了很久,终于解决了这个问题。 - Bruno 82

1
我遇到了同样的问题。打开你项目文件夹下的Gemfile,将 gem 'sqlite3' 这一行改为 gem 'sqlite3', '< 1.4',就像 @Unixmonkey 建议的那样。
gem 'sqlite3' 变为 gem 'sqlite3', '< 1.4'

0
  1. 不要在 Windows 上运行你的代码
  2. 如果你真的必须要,在使用 gem 1.3.13 版本
gem install sqlite3 -v 1.3.13

这不会安装Windows的本地扩展,因此不会导致任何错误。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接