问题描述
Ruby 1.9.3
Gemfile的一部分
#...............
gem "pony"
gem "bcrypt-ruby", :require => "bcrypt"
gem "nokogiri"
#..................
当我尝试安装 gems 时,我收到一个错误
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
并得到一个错误。
我错过了什么?
最佳解决方法
有类似的问题:
通常,解决方案是:
sudo apt-get install ruby-dev
或者,如果这不起作用,取决于您的ruby版本,运行如下:
sudo apt-get install ruby1.9.1-dev
应该解决你的问题。
还是行不通?安装ruby-dev后请尝试以下操作:
sudo apt-get install make
次佳解决方法
我在尝试安装jquery-rails时遇到了同样的问题。修复是
sudo apt-get install zlibc zlib1g zlib1g-dev
第三种解决方法
我发现我需要安装另一个版本的ruby。所以运行命令
$ sudo apt-get install ruby1.9.1-dev
然后尝试安装扩展
如果遇到问题,告诉您没有g ++,可以运行以下命令进行安装
$ sudo apt-get install g++
第四种方法
-
确保已安装
ruby-dev
-
确保已安装
make
-
如果仍然出现错误,请查找建议的包。如果您尝试安装类似
gem install pg
的东西,您还需要安装liblibpq-dev
(sudo apt-get install libpq-dev
)。
第五种方法
如果将来有人遇到这个问题,我正在使用Mac,只需使用’xcode-select –install’安装命令行工具