启动Rails时出现sqlite3错误

3

我开始检查版本是否合适,确认我的系统符合最低要求后,执行以下命令创建新应用:

rails new app

当创建完新应用后,我会收到以下提示信息:

         run  bundle install
/var/lib/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/ui.rb:36:in `initialize': undefined method `[]' for #<Thor::Shell::Color:0x95890e0> (NoMethodError)
    from /usr/lib/ruby/vendor_ruby/bundler/cli.rb:12:in `new'
    from /usr/lib/ruby/vendor_ruby/bundler/cli.rb:12:in `initialize'
    from /usr/lib/ruby/vendor_ruby/bundler/vendor/thor.rb:263:in `new'
    from /usr/lib/ruby/vendor_ruby/bundler/vendor/thor.rb:263:in `dispatch'
    from /usr/lib/ruby/vendor_ruby/bundler/vendor/thor/base.rb:386:in `start'
    from /var/lib/gems/1.9.1/gems/bundler-1.3.5/bin/bundle:20:in `block in <main>'
    from /var/lib/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/friendly_errors.rb:3:in `with_friendly_errors'
    from /var/lib/gems/1.9.1/gems/bundler-1.3.5/bin/bundle:20:in `<main>'

我进入了新创建的Rails应用程序。然后运行bundle install开始安装,但是遇到了以下错误信息:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb 
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
*** 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=/usr/bin/ruby1.9.1
    --with-sqlite3-dir
    --without-sqlite3-dir
    --with-sqlite3-include
    --without-sqlite3-include=${sqlite3-dir}/include
    --with-sqlite3-lib
    --without-sqlite3-lib=${sqlite3-dir}/lib
    --enable-local
    --disable-local


Gem files will remain installed in /home/helio/.bundler/tmp/23089/gems/sqlite3-1.3.8 for inspection.
Results logged to /home/helio/.bundler/tmp/23089/gems/sqlite3-1.3.8/ext/sqlite3/gem_make.out

An error occurred while installing sqlite3 (1.3.8), and Bundler
cannot continue.
Make sure that `gem install sqlite3 -v '1.3.8'` succeeds before
bundling.

我尝试安装sqlite3,但是出现了错误提示:

Building native extensions.  This could take a while...
ERROR:  Error installing sqlite3:
    ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
*** 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=/usr/bin/ruby1.9.1
    --with-sqlite3-dir
    --without-sqlite3-dir
    --with-sqlite3-include
    --without-sqlite3-include=${sqlite3-dir}/include
    --with-sqlite3-lib
    --without-sqlite3-lib=${sqlite3-dir}/lib
    --enable-local
    --disable-local


Gem files will remain installed in /var/lib/gems/1.9.1/gems/sqlite3-1.3.8 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/sqlite3-1.3.8/ext/sqlite3/gem_make.out

我也尝试过写两行建议信息:port install sqlite3 +universalyum install sqlite-devel,但它们都没有起作用。 - Hell0
4个回答

9

我曾经遇到同样的错误,尝试创建一个新的Rails项目时出现了这个错误:sqlite3.h is missing,这意味着libsqlite3-dev可能缺失(我在Ubuntu和Sqlite3方面很陌生)。可以在这里找到答案:安装sqlite头文件

~$ sudo apt-get install sqlite3
~$ sudo apt-get install libsqlite3-dev
~$ bundle install

之后,rails server 对我来说很好用。我在本机上看到了我的欢迎使用页面。


1
对我来说,我在MacOS上遇到了一个错误,后来发现是缺少GNU MP库。这在~/.rvm/gems/ruby-2.1.3/extensions/x86_64-darwin-13/2.1.0-static/sqlite3-1.3.9/mkmf.log文件中提到了。缺少了-lgmp。brew显示库已经存在,但我认为Xcode想知道的是:
我的尝试... $ brew install gmp Warning: gmp-6.0.0a already installed ✔ ~/.rvm/gems/ruby-2.1.3/extensions/x86_64-darwin-13/2.1.0-static/sqlite3-1.3.9 $ brew install gmp4 Warning: gmp4-4.3.2 already installed ✔ ~/.rvm/gems/ruby-2.1.3/extensions/x86_64-darwin-13/2.1.0-static/sqlite3-1.3.9

$ ls -altd /usr/local/lib/libgmp* lrwxr-xr-x 1 si staff 40 Jul 31 15:48 /usr/local/lib/libgmp.10.dylib -> ../Cellar/gmp/6.0.0a/lib/libgmp.10.dylib lrwxr-xr-x 1 si staff 33 Jul 31 15:48 /usr/local/lib/libgmp.a -> ../Cellar/gmp/6.0.0a/lib/libgmp.a lrwxr-xr-x 1 si staff 37 Jul 31 15:48 /usr/local/lib/libgmp.dylib -> ../Cellar/gmp/6.0.0a/lib/libgmp.dylib lrwxr-xr-x 1 si staff 41 Jul 31 15:48 /usr/local/lib/libgmpxx.4.dylib -> ../Cellar/gmp/6.0.0a/lib/libgmpxx.4.dylib lrwxr-xr-x 1 si staff 35 Jul 31 15:48 /usr/local/lib/libgmpxx.a -> ../Cellar/gmp/6.0.0a/lib/libgmpxx.a lrwxr-xr-x 1 si staff 39 Jul 31 15:48 /usr/local/lib/libgmpxx.dylib -> ../Cellar/gmp/6.0.0a/lib/libgmpxx.dylib ✔ ~/.rvm/gems/ruby-2.1.3/extensions/x86_64-darwin-13/2.1.0-static/sqlite3-1.3.9

$ otool -L /usr/local/lib/libgmpxx.dylib /usr/local/lib/libgmpxx.dylib: /usr/local/lib/libgmpxx.4.dylib (compatibility version 9.0.0, current version 9.0.0) /usr/local/Cellar/gmp/6.0.0a/lib/libgmp.10.dylib (compatibility version 13.0.0, current version 13.0.0) /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

$ gem install sqlite3 '1.3.9' 正在构建本地扩展,可能需要一些时间... 成功安装sqlite3-1.3.9 错误:无法在任何存储库中找到有效的gem '1.3.9' (>= 0) 已安装1个gem

尽管出现了ERROR消息,但它似乎仍然安装成功。


1

首先需要在您的系统上安装sqlite3。Rails缺少这些库。


尝试安装sqlite3后,请编辑条目并仅返回已翻译的文本。 - Hell0
SQLite3 已经安装 SQLite 版本 3.7.13,发布于 2012 年 06 月 11 日 02:05:22 输入“.help”获取帮助 输入 SQL 语句以“;”结束 sqlite> - Hell0

0
问题出在Gemfile文件中。教程中有一条注释说:默认情况下,Windows和Mac都已安装了Java运行时脚本。而Linux没有预装。需要单独安装。但是解决方法非常简单。 第一步是清除Gemfile文件中涉及运行时的那一行。 第二步是运行bundle install命令。Bundler会安装必要的软件,问题就解决了。

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