无法安装gem – 无法构buildgem本机扩展 – 无法加载此类文件 – mkmf(LoadError)

Ruby 1.9.3

Gemfile的一部分

#............... gem "pony" gem "bcrypt-ruby", :require => "bcrypt" gem "nokogiri" #.................. 

当我试图安装gem,我得到一个错误

 alex@ubuntu:~/$ bundle Fetching gem metadata from http://rubygems.org/......... Fetching gem metadata from http://rubygems.org/.. Enter your password to install the bundled RubyGems to your system: #####............................................................ Installing bcrypt-ruby (3.0.1) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /usr/bin/ruby1.9.1 extconf.rb /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError) from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from extconf.rb:36:in `<main>' Gem files will remain installed in /home/alex/.bundler/tmp/5526/gems/bcrypt-ruby-3.0.1 for inspection. Results logged to /home/alex/.bundler/tmp/5526/gems/bcrypt-ruby-3.0.1/ext/mri/gem_make.out An error occurred while installing bcrypt-ruby (3.0.1), and Bundler cannot continue. Make sure that `gem install bcrypt-ruby -v '3.0.1'` succeeds before bundling. 

然后,我正在这样做

 sudo gem install bcrypt-ruby -v '3.0.1' Building native extensions. This could take a while... ERROR: Error installing bcrypt-ruby: ERROR: Failed to build gem native extension. /usr/bin/ruby1.9.1 extconf.rb /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError) from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from extconf.rb:36:in `<main>' Gem files will remain installed in /var/lib/gems/1.9.1/gems/bcrypt-ruby-3.0.1 for inspection. Results logged to /var/lib/gems/1.9.1/gems/bcrypt-ruby-3.0.1/ext/mri/gem_make.out 

并获得一个错误。

我错过了什么?

也有类似的问题:

  • `require':没有这样的文件加载 – mkmf(LoadError)
  • 无法构buildgem本机扩展(mkmf(LoadError)) – Ubuntu 12.04

通常,解决scheme是:

sudo apt-get install ruby​​-dev

或者,如果这不起作用,取决于你的ruby版本 ,运行如下:

sudo apt-get install ruby​​1.9.1-dev

应该解决你的问题。


还是行不通? 安装ruby-dev后试试以下几点:

sudo apt-get install make

我有同样的问题试图安装jQuery的铁轨。 解决方法是

 sudo apt-get install zlibc zlib1g zlib1g-dev 
  1. 确保安装了ruby-dev
  2. 确保安装
  3. 如果仍然出现错误,请查找build议的软件包。 如果你想安装像gem install pg这样的东西,你还需要安装lib libpq-devsudo apt-get install libpq-dev )。

如果有人在将来有这个问题,我正在使用一个Mac,只需要安装命令行工具使用'xcode-select –install'

我发现我需要安装另一个版本的ruby。 所以运行命令

 $ sudo apt-get install ruby1.9.1-dev 

然后尝试安装扩展

如果遇到问题,告诉您没有g ++,则可以运行以下命令进行安装

 $ sudo apt-get install g++ 

这也有助于确保安装libmysqlclient-dev(Ubuntu 14.04)

在Mac中,对我来说这个工作:

 CONFIGURE_OPTS="--enable-shared" rbenv install 2.2.2 

经过一些search解决scheme后,事实certificate,需要-dev包,不只是ruby1.8。 所以如果你有ruby1.9.1这样做

 sudo apt-get install ruby1.9.1-dev 

或者安装通用的ruby版本,使用(根据@lamplightdev评论):

 sudo apt-get install ruby-dev 

应该修复它。

尝试findmkmf来查看文件是否真的存在。