由于缺少sqlite3 gem,Rails 4.0rc1 app无法运行

时间:2013-05-13 03:29:17

标签: ruby-on-rails sqlite bundler ruby-on-rails-4

我第一次尝试安装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'添加到您的Gemfile。

它存在于我的Gemfile中:

gem 'sqlite3'

我尝试多次运行bundle install并且甚至没有在所有其他宝石中列出它。

更新 :我尝试以两种不同的方式安装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 <top (required)>'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.7/lib/sqlite3.rb:2:in `<top (required)>'
        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 `<top (required)>'
        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 <top (required)>'
        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 `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

6 个答案:

答案 0 :(得分:7)

非常烦人,但我终于明白了。您基本上必须执行以下操作:

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

答案 1 :(得分:3)

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

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

$ gem install sqlite3 --platform=ruby

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

答案 2 :(得分:0)

下载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,您将收到错误消息。

答案 3 :(得分:0)

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

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

在这里尝试了几乎所有答案后,最终为我做的事情(除非我产生幻觉)是https://stackoverflow.com/a/16524605/765352How do I install sqlite3 for Ruby on Windows?中的最后一条评论)。

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

通过提供链接来详细阐述他的答案:

  1. 转到http://www.sqlite.org(具体为http://sqlite.org/download.html)并下载:

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

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

    2. 进入ruby shell,然后输入

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

      < / LI>

      你应该看到

      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,它被证明是重量级的。一如既往地感谢Google。

      参考文献:

      • 这个线程;

      • 撰写https://stackoverflow.com/a/16524605/765352;

      • 的人
      • 一堆线索谈论sqlite.org;

      • StackExchange,不放弃我;

      • 我,因为不放弃StackExchange;

      • 所有的信徒都在那里;

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

答案 4 :(得分:0)

看一下这个决议:

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

答案 5 :(得分:0)

谢谢大家,这对我安装sqlite3有用:

下载sqlite-dll-win64-x64-3260000.zip,sqlite-tools-win32-x86-3260000.zip和sqlite-autoconf-3260000.tar.gz。

将sqlite3.h和sqlite3ext.h放置在名为 include

的文件夹中

将shell.c,sqlite3.c,sqlite3.def和sqlite3.dll放在名为 lib

的文件夹中
gem install sqlite3 --platform=ruby -- --with-sqlite3-lib=c:/Devkit/sqlite3/lib --with-sqlite3-include=c:/Devkit/sqlite3/include
gem install data_mapper --platform=ruby -- --with-sqlite3-lib=c:/Devkit/sqlite3/lib --with-sqlite3-include=c:/Devkit/sqlite3/include
gem install dm-sqlite-adapter --platform=ruby -- --with-sqlite3-lib=c:/Devkit/sqlite3/lib --with-sqlite3-include=c:/Devkit/sqlite3/include