Ruby-on-rails 无法安装 gem - 无法构建 gem 本机扩展 - 无法加载此类文件 - mkmf (LoadError)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13767725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to install gem - Failed to build gem native extension - cannot load such file -- mkmf (LoadError)
提问by Alexandre
Ruby 1.9.3
红宝石 1.9.3
The part of Gemfile
Gemfile 的部分
#...............
gem "pony"
gem "bcrypt-ruby", :require => "bcrypt"
gem "nokogiri"
#..................
When I'm trying to install gems, I get an error
当我尝试安装 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.
Then I'm doing this
然后我在做这个
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
and getting an error as well.
并得到一个错误。
What did I miss?
我错过了什么?
回答by MrYoshiji
There are similar questions:
有类似的问题:
- `require': no such file to load -- mkmf (LoadError)
- Failed to build gem native extension (mkmf (LoadError)) - Ubuntu 12.04
Usually, the solution is:
通常,解决方法是:
sudo apt-get install ruby-dev
sudo apt-get install ruby-dev
Or, if that doesn't work, depending on your ruby version, run something like:
或者,如果这不起作用,根据您的 ruby 版本,运行如下命令:
sudo apt-get install ruby1.9.1-dev
须藤 apt-get 安装 ruby1.9.1-dev
Should fix your problem.
应该解决你的问题。
Still not working? Try the following after installing ruby-dev:
还是行不通?安装 ruby-dev 后尝试以下操作:
sudo apt-get install make
sudo apt-get install make
回答by Dmitry S.
For WSL (Windows Subsystem for Linux) you need install build-essentialpackage:
对于 WSL(Linux 的 Windows 子系统),您需要安装build-essential包:
sudo apt install build-essential
回答by B2Pi
I had the same issue trying to install jquery-rails. The fix was
我在尝试安装 jquery-rails 时遇到了同样的问题。修复是
sudo apt-get install zlibc zlib1g zlib1g-dev
回答by hmjha
I found that I needed to install another version of ruby. So running the command
我发现我需要安装另一个版本的 ruby。所以运行命令
$ sudo apt-get install ruby1.9.1-dev
and then attempt to install the extension
然后尝试安装扩展
If you run into issues where it is telling you that you don't have g++ you can run the following command to install it
如果您遇到它告诉您没有 g++ 的问题,您可以运行以下命令来安装它
$ sudo apt-get install g++
回答by Jerome
Just finished a 2 hour wild goose chase trying to solve this. None of the posted answers worked for me. Im on a Mac (Mojave Version 10.14.6, Xcode Version 11.3).
刚刚完成了 2 小时的野鹅追逐试图解决这个问题。没有一个已发布的答案对我有用。我在 Mac 上(Mojave 版本 10.14.6,Xcode 版本 11.3)。
It turns out the ruby file headers were missing so i had to run open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
事实证明 ruby 文件头丢失了所以我不得不运行 open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
That didnt work for me at first because the version of CommandLineTools i had installed did not have the "Packages" folder. So i uninstalled and reinstalled like this:
起初这对我不起作用,因为我安装的 CommandLineTools 版本没有“Packages”文件夹。所以我像这样卸载并重新安装:
rm -rf /Library/Developer/CommandLineTools
rm -rf /Library/Developer/CommandLineTools
xcode-select --install
xcode-select --install
Then i ran the previous command again:
然后我再次运行上一个命令:
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
After install the error was fixed!
安装后错误已修复!
回答by NateW
In case anyone in the future had this problem, I'm using a Mac and just had to install the Command Line Tools using 'xcode-select --install'
如果将来有人遇到此问题,我使用的是 Mac,只需使用“xcode-select --install”安装命令行工具
回答by hazmat
- Make sure
ruby-devis installed - Make sure
makeis installed - If you still get the error, look for suggested packages. If you are trying to install something like
gem install pgyou will also need to install the liblibpq-dev(sudo apt-get install libpq-dev).
- 确保
ruby-dev已安装 - 确保
make已安装 - 如果仍然出现错误,请查找建议的软件包。如果您尝试安装类似的东西,
gem install pg您还需要安装 liblibpq-dev(sudo apt-get install libpq-dev)。
回答by KLaw
It also helps to ensure libmysqlclient-dev is installed (Ubuntu 14.04)
它还有助于确保安装 libmysqlclient-dev (Ubuntu 14.04)
回答by Mohammed
This worked for me.
bundle config --global build.snappy --with-opt-dir="$(brew --prefix snappy)"
这对我有用。
bundle config --global build.snappy --with-opt-dir="$(brew --prefix snappy)"
回答by rubyu2
In Mac, for me this works:
在 Mac 中,对我来说这有效:
CONFIGURE_OPTS="--enable-shared" rbenv install 2.2.2

