[英]Unable to install gem - Failed to build gem native extension - cannot load such file -- mkmf (LoadError)
Ruby 1.9.3 Ruby 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?我错过了什么?
There are similar questions:有类似的问题:
Usually, the solution is:通常,解决方案是:
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
Should fix your problem.应该解决你的问题。
Still not working?还是行不通? Try the following after installing ruby-dev:
安装 ruby-dev 后尝试以下操作:
sudo apt-get install make
对于 WSL(Linux 的 Windows 子系统),您需要安装build-essential
软件包:
sudo apt install build-essential
Just finished a 2 hour wild goose chase trying to solve this.刚刚完成了 2 小时的野鹅追逐,试图解决这个问题。 None of the posted answers worked for me.
发布的答案都不适合我。 Im on a Mac (Mojave Version 10.14.6, Xcode Version 11.3).
我在 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.起初这对我不起作用,因为我安装的 CommandLineTools 版本没有“Packages”文件夹。 So i uninstalled and reinstalled like this:
所以我像这样卸载并重新安装:
rm -rf /Library/Developer/CommandLineTools
xcode-select --install
Then i ran the previous command again:然后我再次运行前面的命令:
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
After install the error was fixed!安装后错误已修复!
I had the same issue trying to install jquery-rails.我在尝试安装 jquery-rails 时遇到了同样的问题。 The fix was
修复是
sudo apt-get install zlibc zlib1g zlib1g-dev
万一将来有人遇到这个问题,我使用的是 Mac,只需要使用“xcode-select --install”安装命令行工具
I found that I needed to install another version of ruby.我发现我需要安装另一个版本的 ruby。 So running the command
所以运行命令
$ 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++
I created a small hackMD to install cocoapods on MacOS 10.15 (Catalina) and 11 (Big Sur)我创建了一个小型 hackMD 来在 MacOS 10.15 (Catalina) 和 11 (Big Sur) 上安装 cocoapods
https://hackmd.io/@sBJPlhRESGqCKCqV8ZjP1A/S1UY3W7HP https://hackmd.io/@sBJPlhRESGqCKCqV8ZjP1A/S1UY3W7HP
Make sure you have xcode components are installed.确保您已安装 xcode 组件。
Download 'Command Line Tools' (about 500MB) directly from this link (Requires you to have apple account) https://developer.apple.com/downloads/index.action直接从此链接下载“命令行工具”(约 500MB)(要求您拥有苹果帐户) https://developer.apple.com/downloads/index.action
Install the downloaded file安装下载的文件
Click on Install点击安装
Install COCOAPODS files in terminal sudo gem install -n /usr/local/bin cocoapods
在终端安装 COCOAPODS 文件
sudo gem install -n /usr/local/bin cocoapods
For MacOS users:对于 MacOS 用户:
Just do this and easily it will solve your problem:只需这样做,它就可以轻松解决您的问题:
brew install cocoapods
ruby-dev
is installedruby-dev
make
is installedmake
gem install pg
you will also need to install the lib libpq-dev
( sudo apt-get install libpq-dev
).gem install pg
之类的东西,您还需要安装 lib libpq-dev
( sudo apt-get install libpq-dev
)。This worked for me.这对我有用。
bundle config --global build.snappy --with-opt-dir="$(brew --prefix snappy)"
它还有助于确保安装 libmysqlclient-dev (Ubuntu 14.04)
What ended up working for me after a few hours of pain..经过几个小时的痛苦,最终对我有用的东西..
if you're running brew..如果你正在运行 brew..
brew install ruby
in the terminal output/log, identify the path where ruby was installed, brew suggests 'You may want to add this to your PATH', so that's what we'll do.在终端输出/日志中,确定 ruby 的安装路径,brew 建议“您可能希望将其添加到 PATH”中,这就是我们要做的。 For example, mine is
例如,我的是
/usr/local/lib/ruby/gems/3.0.0/bin
Add this to your path by running (omitting braces)通过运行(省略大括号)将其添加到您的路径中
echo 'export PATH"{the_path_you_found_above}:$PATH"' >> ~/.bash_profile
then update your environment by running然后通过运行更新您的环境
source ~/.bash_profile
now, try running your install, ie,现在,尝试运行您的安装,即
sudo gem install middleman
If you are a mac user you must need to update the clang version being used I burnt hours searching this and installed uninstalled xcode commandline tools but it didn't help.如果您是 mac 用户,则必须更新正在使用的 clang 版本我花了好几个小时搜索这个并安装了卸载的 xcode 命令行工具,但它没有帮助。 I ran
gcc -v
and Apple clang version 11.0.0 (clang-1100.0.33.8
was the output. Then I ran xcode-select -s /Library/Developer/CommandLineTools/
and clang version was updated to Apple clang version 12.0.0 (clang-1200.0.32.29)
. bundle install was successful after that. I hope this may help.我运行
gcc -v
和Apple clang version 11.0.0 (clang-1100.0.33.8
。然后我运行xcode-select -s /Library/Developer/CommandLineTools/
并将 clang 版本更新为Apple clang version 12.0.0 (clang-1200.0.32.29)
. 之后捆绑安装成功。我希望这可能会有所帮助。
I was making a word search app and I had to install cocoapods and after formatting my mac and reinstalling xcode, I still got the error when I wanted to install cocoapods.我正在制作一个单词搜索应用程序,我必须安装 cocoapods,在格式化我的 mac 并重新安装 xcode 后,当我想安装 cocoapods 时仍然出现错误。
And the solution for this was the following:解决方案如下:
It looks like CocoaPods 1.9.0, the latest version as of this writing, depends on a newer version of Ruby than 2.3.7.看起来 CocoaPods 1.9.0 是撰写本文时的最新版本,它依赖于比 2.3.7 更新的 Ruby 版本。 But macOS Mojave only includes Ruby 2.3.7, so you have a few different options.
但 macOS Mojave 仅包含 Ruby 2.3.7,因此您有几个不同的选择。
Upgrade to macOS Catalina and get Ruby 2.6.3
Use Ruby Version Manager to install a newer version of Ruby
Install an older version of CocoaPods
sudo gem install cocoapods -v 1.8.4
I did 3:我做了3:
sudo gem install cocoapods -v 1.8.4 sudo gem install cocoapods -v 1.8.4
在 Mac 中,对我来说这是有效的:
CONFIGURE_OPTS="--enable-shared" rbenv install 2.2.2
After some search for a solution, it turns out the -dev package is needed, not just ruby1.8.经过一番寻找解决方案后,发现需要 -dev 包,而不仅仅是 ruby1.8。 So if you have ruby1.9.1 doing
所以如果你有 ruby1.9.1 做
sudo apt-get install ruby1.9.1-dev
or to install generic ruby version, use (as per @lamplightdev comment):或安装通用 ruby 版本,使用(根据@lamplightdev 评论):
sudo apt-get install ruby-dev
should fix it.应该修复它。
Try to locate mkmf to see if the file is actually there.尝试定位 mkmf 以查看该文件是否确实存在。
brew install cocoapods
对我很有用
first set your Xcode version on the terminal:首先在终端上设置您的 Xcode 版本:
sudo xcode-select -switch /Applications/Xcode.app
then install:然后安装:
sudo gem install cocoapods
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.