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

也会得到一个错误。

我错过了什么?


当前回答

为了破案,我花了两个小时白费力气。贴出来的答案没有一个对我有用。我在Mac上(Mojave版本10.14.6,Xcode版本11.3)。

结果发现ruby文件头不见了,所以我不得不运行open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

起初,这对我来说并不管用,因为我安装的CommandLineTools版本没有“Packages”文件夹。所以我像这样卸载和重新安装:

rm -rf /Library/Developer/CommandLineTools . xml

xcode-select——安装

然后我再次运行前面的命令:

打开/图书馆/开发/ CommandLineTools /包/ macOS_SDK_headers_for_macOS_10.14.pkg

安装后错误被修复!

其他回答

它还有助于确保libmysqlclient-dev已安装(Ubuntu 14.04)

在Mac中,这对我来说是有效的:

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

我创建了一个小hackMD来在MacOS 10.15 (Catalina)和11 (Big Sur)上安装cocoapods

https://hackmd.io/@sBJPlhRESGqCKCqV8ZjP1A/S1UY3W7HP

在 MacOS Catalina (MacOS 10.15.X) 和 Big Sur (MacOS 11) 上安装 Cocoapods

确保你安装了xcode组件。 直接从这个链接下载“命令行工具”(约500MB)(需要你有苹果账号) https://developer.apple.com/downloads/index.action 安装下载的文件 点击安装 在终端安装COCOAPODS文件 Sudo gem install -n /usr/local/bin cocoapods . sh

对于WSL (Windows Subsystem For Linux),您需要安装build-essential包:

sudo apt install build-essential

MacOS用户:

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

brew install cocoapods