由于缺少sqlite3 gem,Rails 4.0rc1应用程序未运行

我第一次尝试安装Rails 4.0。 在带有Ruby 2.0 x64的Windows 8上。 冉:

gem install rails --version 4.0.0.rc1 --no-ri --no-rdoc 

然后我跑:

 rails new test_app cd test_app rails s 

localhost:3000的网页报告以下错误:

为数据库适配器指定’sqlite3’,但未加载gem。 将gem’sqlite3 gem 'sqlite3'添加到您的Gemfile中。

它在我的Gemfile中:

 gem 'sqlite3' 

我尝试多次运行bundle install ,它甚至没有在所有其他gem中列出它。

更新 :我尝试以两种不同的方式安装sqlite3 gem,两者都使用从DevKit的msys.bat文件打开的终端。 @szines下面提到的方式给了我以下错误:

 $ gem install sqlite3 --platform=ruby -- --with-opt-dir=c:/sqlite-amalgamation-3071602 Temporarily enhancing PATH to include DevKit... Building native extensions with: '--with-opt-dir=c:/sqlite-amalgamation-3071602' This could take a while... ERROR: Error installing sqlite3: ERROR: Failed to build gem native extension. c:/Ruby200-x64/bin/ruby.exe extconf.rb --with-opt-dir=c:/sqlite-amalgamation-3071602 checking for sqlite3.h... yes checking for sqlite3_libversion_number()... -lsqlite3 sqlite3 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 --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:/Ruby200-x64/bin/ruby --with-sqlite3-dir --without-sqlite3-dir --with-sqlite3-include --without-sqlite3-include=${sqlite3-dir}/include --with-sqlite3-lib --without-sqlite3-lib=${sqlite3-dir}/ --enable-local --disable-local --with-sqlite3lib --without-sqlite3lib Gem files will remain installed in c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.7 for inspection. Results logged to c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.7/ext/sqlite3/gem_make.out 

另一方面,我使用sqlite.org的autoconf包,我能够编译和安装sqlite3 gem。 但是,当我尝试打开Rails服务器时,我收到以下错误:

 C:\Users\me\RubymineProjects\my_project>rails s C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.7/lib/sqlite3.rb:6:in `require': cannot load such file -- sqlite3/sqlite3_native (LoadError) from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.7/lib/sqlite3.rb:6:in `rescue in ' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.7/lib/sqlite3.rb:2:in `' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler.rb:132:in `require' from C:/Users/me/RubymineProjects/my_project/config/application.rb:7:in `' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/commands.rb:78:in `require' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/commands.rb:78:in `block in ' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/commands.rb:75:in `tap' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/commands.rb:75:in `' from bin/rails:4:in `require' from bin/rails:4:in `' 

很烦人,但我终于搞定了。 你基本上必须做以下事情:

  1. 下载准备由Luis Lavena 编译的sqlite文件 (这是x64)
  2. 用7-zip解压缩到`c:\ sqlite3
  3. 从您取消存档DevKit的DevKit文件夹中运行msys.bat
  4. 运行gem install sqlite3 --platform=ruby -- --with-opt-dir=C:/sqlite3

我在使用Ruby 2.0运行Rails版本4.0.0的Mac OS X上,问题是sqlite3没有更新到兼容版本(警告并没有这么说)。

以下是我能够解决问题的方法:

 $ gem install sqlite3 --platform=ruby 

这让我想到了最新版本的sqlite3是1.3.7。 然后我相应地更新了gemfile中的sqlite3 gem。 就这么简单。

*这个答案适用于Ruby 2.0.0 x86,而不是x64。

我想我拥有它。 圣杯。 牛奶和蜂蜜的土地。 在印第安纳琼斯的那个盒子里疯狂的灯光射出了。 不会在阳光下融化的冰淇淋。

在尝试了几乎每个答案之后,最终为我做了什么(除非我产生了幻觉)是https://stackoverflow.com/a/16524605/765352 ( 我如何在Windows上为Ruby安装sqlite3的最后一条评论? )。

我使用RailsInstaller版本的Ruby在Windows 8上运行Ruby 2.0.0 x86。

只是通过提供链接来详细说明他的答案:

  1. 访问http://www.sqlite.org (特别是http://sqlite.org/download.html )并下载:

(我不知道是否需要最后两个。而且,我不会再回到兔子洞里去检查。)

  1. 将所有这些ZIP解压缩到您选择的目录中。 我使用了“sqlite-amalgamation-301700”。 (DIR)。

  2. 进入你的rubyshell,然后输入

    gem install sqlite3 –platform = ruby​​ – –with-sqlite3-dir = c:/ sqlite-amalgamation-3071602 –with-sqlite3-include = c:/ sqlite-amalgamation-3071602

你应该看到

 C:\xx\>gem install sqlite3 --platform=ruby -- --with-sqlite3-dir=c:/sqlite-amalgamation-3071602 --with-sqlite3-include=c:/sqlite-amalgamation-3071602 Temporarily enhancing PATH to include DevKit... Building native extensions with: '--with-sqlite3-dir=c:/sqlite-amalgamation-3071602 --with-sqlite3-include=c:/sqlite-amalgamation-3071602' This could take a while... Successfully installed sqlite3-1.3.7 Parsing documentation for sqlite3-1.3.7 unable to convert "\x90" from ASCII-8BIT to UTF-8 for lib/sqlite3/sqlite3_native.so, skipp ing Installing ri documentation for sqlite3-1.3.7 Done installing documentation for sqlite3 (3 sec). 1 gem installed 

Booyah。 拿那个,自动编译什么都没有。 并且不用感谢SQLITE,它被certificate是重量级的。 一如既往地感谢Google。

参考文献:

  • 这个线程;

  • 写这篇文章的人是https://stackoverflow.com/a/16524605/765352 ;

  • 一堆线索谈论sqlite.org;

  • StackExchange,不放弃我;

  • 我,因为不放弃StackExchange;

  • 所有的信徒都在那里;

  • 我的制片人和经理,谁爱我(我爱你Al)。

下载sqlite源文件,并使用特殊参数构建sqlite gem。

  • 下载sqlite源代码。
  • 在您的PC上创建一个sqlite文件夹。 例如:c:/ sqlite
  • 在此文件夹中创建三个子文件夹:c:/ sqlite / include,c:/ sqlite / lib,c:/ sqlite / bin
  • 复制源文件:

c:/sqlite/bin => sqlite3.exe

c:/sqlite/include => sqlite3.h sqlite3ext.h

c:/sqlite/lib => libsqlite3.a sqlite3.la

  • 使用卸载以前的sqlite gem

gem uninstall sqlite3

  • 需要兼容的DevKit,适用于64位系统x64版本。
  • 使用以下命令安装兼容的gem。 (不要忘记第二个空的两个破折号。)

gem install sqlite3 --platform=ruby -- --with-opt-dir=c:/sqlite

要小心,如果您以后运行bundle update命令并且您看到bundler安装了’官方’sqlite gem,则必须卸载’old’版本。 如果您有更多版本的sqlite,您将收到错误消息。

看看这个的分辨率:

  • Rails-4在Sqlite3上失败

在这种情况下,最近的Bundler版本中存在一个错误。 预发布的Bundler解决了这个问题。