sqlite3 gem 无法安装
Posted
技术标签:
【中文标题】sqlite3 gem 无法安装【英文标题】:sqlite3 gem fails to install 【发布时间】:2011-06-28 21:09:36 【问题描述】:我正在尝试在 OS X 10.6 上安装“sqlite3-ruby”gem(或“sqlite3”gem)。我正在使用 ruby-1.9.2,目前得到以下信息:
$ sqlite3 --version
3.7.4
$ sudo gem install sqlite3
Building native extensions. This could take a while...
ERROR: Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.
/Users/folken/.rvm/rubies/ruby-1.9.2-head/bin/ruby extconf.rb
checking for sqlite3.h... *** 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=/Users/folken/.rvm/rubies/ruby-1.9.2-head/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/lib
/Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:452:in `try_cpp'
from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:853:in `block in find_header'
from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for'
from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:280:in `block (2 levels) in postpone'
from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone'
from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:276:in `postpone'
from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for'
from /Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:852:in `find_header'
from extconf.rb:28:in `<main>'
Gem files will remain installed in /Users/folken/.rvm/gems/ruby-1.9.2-head/gems/sqlite3-1.3.3 for inspection.
以下是which&whereis的结果,sqlite3.h位于/opt/local/include:
$ which sqlite3
/opt/local/bin/sqlite3
$ whereis sqlite3
/usr/bin/sqlite3
我也尝试过传递以下内容:
sudo gem install sqlite3 -- --with-sqlite3-include /opt/local/include --with-sqlite3-lib /opt/local/lib
sudo gem install sqlite3 -- --with-sqlite3-dir /opt/local/bin
结果如下:
ERROR: Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.
/Users/folken/.rvm/rubies/ruby-1.9.2-head/bin/ruby extconf.rb --with-sqlite3-dir /usr/bin/sqlite3
*** 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=/Users/folken/.rvm/rubies/ruby-1.9.2-head/bin/ruby
--with-sqlite3-dir
/Users/folken/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:1336:in `dir_config': undefined method `split' for true:TrueClass (NoMethodError)
from extconf.rb:9:in `<main>'
也在 /Users/folken/.rvm/gems/ruby-1.9.2-head/gems 下: sqlite-ruby-2.2.3 sqlite3-1.3.3
在 RVM 下,我有 ruby-1.8.7 并且 sqlite3 gem 可以很好地加载,但经过大量谷歌搜索后,我还没有找到适合我的解决方案。任何帮助都非常感谢(即使它涉及手动安装/hacky 开始工作)。
【问题讨论】:
您是否像它告诉您的那样检查了 makefile 日志?它包含什么? 你有gcc吗?尝试在你的 shell 中输入 gcc @Michael - 是的,我有 gcc,@Jergason - 我不确定这个 mkmf.log 文件的输出位置,它不在 /Users/folken/.rvm/log/ruby 下-1.9.2-head(或附近的任何地方,它通常被倾倒到哪里?) 你是否安装了 Sqlite 开发库,在 Ubuntu 上执行“sudo apt-get install libsqlite3-dev” @Zimbabao - 我已经使用 apt-get install 安装了 sqlite3-dev,但我在 OS X 上(我刚刚编辑了原始帖子以添加 OS X)。 【参考方案1】:我在安装 sqlite3 时遇到了与您几乎相似的问题,但 sqlite3 gem 无法安装。我看到如下错误消息,
user-name-rajas-macbook-pro:rails3 user-namer$ gem install sqlite3
Building native extensions. This could take a while...
ERROR: Error installing sqlite3:
ERROR: Failed to build gem native extension.
/Users/user-namer/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb
checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... no
sqlite3 is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite3-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
--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=/Users/user-namer/.rvm/rubies/ruby-1.9.2-p180/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/lib
--with-sqlite3lib
--without-sqlite3lib
Gem files will remain installed in /Users/user-namer/.rvm/gems/ruby-1.9.2- p180@rails_3/gems/sqlite3-1.3.3 for inspection.
Results logged to /Users/user-namer/.rvm/gems/ruby-1.9.2-p180@rails_3/gems/sqlite3- 1.3.3/ext/sqlite3/gem_make.out
这对我有用
gem install sqlite3 -- --with-sqlite3-dir=/opt/local
【讨论】:
谢谢你,我花了很长时间才弄清楚这个。 非常感谢,这又省了几个小时的痛苦! 第一批 -- 字符似乎可以解决问题!只是这个 --with-sqlite3-dir=/usr (brew installed sqlite3) 不起作用,但前缀 -- 似乎起作用。 extrea -- 做什么? -- 是一个分隔符,后跟构建标志,帮助编译 gem 所依赖的任何本机代码。从您的控制台运行“gem help install” - 它很好地解释了这些选项。【参考方案2】:我正在使用 ruby 1.9.2.p180 和 rails 3.1.0.rc6 使用 Mac OS X 10.5.8 (Leopard) 来关注 Rails3 in Action 一书,当我跑步时:
rake cucumber:ok
我明白了:
Please install the sqlite3 adapter: `gem install activerecord-sqlite3-adapter` (can't activate sqlite3 (~> 1.3.4, runtime), already activated sqlite3-1.3.3. Make sure all dependencies are added to Gemfile.)
然后我做了:
gem install sqlite3 -- --with-sqlite3-dir=/opt/local
后跟:
bundle install
希望,当需要 sqlite 1.3.5 时,我会在互联网上找到自己的答案。
【讨论】:
【参考方案3】:听起来你还没有安装 XCode。
【讨论】:
【参考方案4】:对于 osx,请确保您已安装 Xcode 并已接受条款。对我来说,我没有同意这些条款(无论出于何种原因,也许 Xcode 最近在我的计算机上安装或更新)。
-
打开 Xcode
如果出现弹出窗口,则同意条款(如果没有弹出窗口,则您可能已经接受条款)。
【讨论】:
以上是关于sqlite3 gem 无法安装的主要内容,如果未能解决你的问题,请参考以下文章
尝试在 mac 上安装 sqlite3“sudo gem install sqlite3”时出错
gem install sqlite3 有效,捆绑安装无效?
无法安装 gem - 无法构建 gem 本机扩展 - 无法加载此类文件 - mkmf (LoadError)