Ruby 1.9.3

Gemfile的部分

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

当我试图安装宝石时,我得到一个错误

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

也会得到一个错误。

我错过了什么?


当前回答

在寻找了一些解决方案后,发现-dev包是需要的,而不仅仅是ruby1.8。如果你有ruby1.9.1

sudo apt-get install ruby1.9.1-dev

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

sudo apt-get install ruby-dev

应该把它修好。

尝试定位mkmf以查看该文件是否确实存在。

其他回答

还有类似的问题:

' require':没有这样的文件加载——mkmf (LoadError) 构建gem本地扩展失败(mkmf (LoadError)) - Ubuntu 12.04

通常,解决方案是:

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

这对我很管用。 捆绑包配置——全局构建。Snappy——with-opt-dir="$(brew -前缀Snappy)"

如果你是mac用户,你必须更新正在使用的clang版本 我花了几个小时搜索这个,并安装了已卸载的xcode命令行工具,但它没有帮助。 我运行gcc -v和Apple clang版本11.0.0 (clang-1100.0.33.8是输出。 然后我运行xcode-select -s /Library/Developer/CommandLineTools/, clang版本更新为Apple clang版本12.0.0 (clang-1200.0.32.29)。 Bundle安装之后就成功了。 我希望这能有所帮助。

MacOS用户:

只要这么做,问题就迎刃而解了:

brew install cocoapods