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

也会得到一个错误。

我错过了什么?


当前回答

在经历了几个小时的痛苦后,我终于找到了工作。

如果你正在运行brew..

brew install ruby

在终端输出/日志中,确定ruby安装的路径,brew建议“您可能想要将此添加到您的path”,所以这就是我们要做的。例如,我的是

/usr/local/lib/ruby/gems/3.0.0/bin

通过运行(省略大括号)将其添加到路径中

echo 'export PATH"{the_path_you_found_above}:$PATH"' >> ~/.bash_profile

然后通过运行更新环境

source ~/.bash_profile

现在,尝试运行您的安装,即,

sudo gem install middleman

其他回答

首先在终端上设置Xcode版本:

sudo xcode-select -switch /Applications/Xcode.app

然后安装:

sudo gem install cocoapods

以防将来有人遇到这个问题,我使用的是Mac,必须使用“xcode-select——install”安装命令行工具。

还有类似的问题:

' 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

我创建了一个小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

我发现我需要安装另一个版本的ruby。所以运行命令

$ sudo apt-get install ruby1.9.1-dev

然后尝试安装扩展

如果您遇到问题,它告诉您没有g++,您可以运行以下命令来安装它

$ sudo apt-get install g++