如何修复损坏的 Ruby 配置

How to fix a broken Ruby config

我使用的是 MacOs High Sierra 10.13.6。 bundle install 不再有效。多年来,我一直在这台机器上使用捆绑器到 运行 快车道。我最近安装了其他软件,我想我弄错了,破坏了配置。

我有以下 Gemfile:

来源“https://rubygems.org

gem 'fastlane', '2.120.0'
gem 'aws-sdk', '2.10.8'
gem 'awscli', '0.2.8'
gem 'rake', '12.0.0'
gem 'danger', '5.4.3'

plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
eval(File.read(plugins_path), binding) if File.exist?(plugins_path)

当我尝试 运行 bundle install 时出现错误:

ERROR: cannot discover where libxml2 is located on your system. please make sure pkg-config is installed.

An error occurred while installing nokogiri (1.8.2), and Bundler cannot continue. Make sure that gem install nokogiri -v '1.8.2' --source 'https://rubygems.org/' succeeds before bundling.

如果我运行:

gem install nokogiri -v '1.8.2'

gem install nokogiri -v 1.8.2 -n /usr/local/bin -- --use-system-libraries

我收到错误:

ERROR: While executing gem ... (Errno::EACCES) Permission denied @ rb_sysopen - /Library/Ruby/Gems/2.3.0/gems/nokogiri-1.8.2/.autotest

我已经尝试更改文件夹的权限 运行:

gem install pkg-config -n /usr/local/bin -- --use-system-libraries
gem install nakogiri -v 1.8.2 -n /usr/local/bin -- --use-system-libraries

根据其中一条错误消息的建议,我也有 运行:

bundle config build.nokogiri --use-system-libraries

在这种情况下,这些命令成功但 bundle install 仍然失败并出现相同的错误。

我安装了 rvm。 然后在我附加的 .zshrc 文件中:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"

那我运行:

rvm reinstall all --force

现在可以正常使用了。