ruby 无法在 OS X“El Capitan”上安装 gems

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31972968/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 06:46:21  来源:igfitidea点击:

Can't install gems on OS X "El Capitan"

rubymacosrubygems

提问by Himanshu Yadav

I am not able to install and run fakes3gem on El Capitan Beta 5.

我无法fakes3在 El Capitan Beta 5 上安装和运行gem。

I tried:

我试过:

sudo gem install fakes3
ERROR:  While executing gem ... (Errno::EPERM)
    Operation not permitted - /usr/bin/fakes3

Then I tried doing it the cocoapods way. It worked for cocoapods but not for fakes3.

然后我试着用 cocoapods 的方式来做。它适用于可可豆,但不适用于假货3。

mkdir -p $HOME/Software/ruby
export GEM_HOME=$HOME/Software/ruby
gem install cocoapods
[...]
1 gem installed
gem install fakes3
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

回答by nschum

Disclaimer:@theTinMan and other Ruby developers often point out not to use sudowhen installing gems and point to things like RVM. That's absolutely true when doing Ruby development. Go ahead and use that.

免责声明:@theTinMan 和其他 Ruby 开发人员经常指出sudo在安装 gems 时不要使用,并指出诸如RVM 之类的东西。在进行 Ruby 开发时,这是绝对正确的。继续使用它。

However, many of us just want some binary that happens to be distributed as a gem (e.g. fakes3, cocoapods, xcpretty…). I definitely don't want to bother with managing a separate ruby. Here are your quicker options:

然而,我们许多人只是想一些二进制碰巧被分配作为宝石(例如fakes3cocoapodsxcpretty...)。我绝对不想费心管理一个单独的 ruby​​。以下是您更快的选择:

Option 1: Keep using sudo

选项 1:继续使用 sudo

Using sudois probably fine if you want these tools to be installed globally.

sudo如果您希望全局安装这些工具,使用可能没问题。

The problem is that these binaries are installed into /usr/bin, which is off-limitssince El Capitan. However, you can install them into /usr/local/bininstead. That's where Homebrewinstall its stuff, so it probablyexists already.

问题是这些二进制文件被安装到/usr/bin,这是自 El Capitan 以来的禁区。但是,您可以将它们安装到/usr/local/bin。这就是Homebrew安装它的东西的地方,所以它可能已经存在。

sudo gem install fakes3 -n/usr/local/bin

Gems will be installed into /usr/local/binand every user on your system can use them if it's in their PATH.

Gems 将被安装到系统中,/usr/local/bin并且您系统上的每个用户都可以使用它们,如果它在他们的PATH 中

Option 2: Install in your home directory (without sudo)

选项 2:安装在您的主目录中(不带 sudo)

The following will install gems in ~/.gemand put binaries in ~/bin(which you should then add to your PATH).

以下将安装 gems~/.gem并将二进制文件放入~/bin(然后您应该将其添加到您的PATH)。

gem install fakes3 --user-install -n~/bin

Make it the default

将其设为默认值

Either way, you can add these parameters to your ~/.gemrcso you don't have to remember them:

无论哪种方式,您都可以将这些参数添加到您的,~/.gemrc这样您就不必记住它们:

gem: -n/usr/local/bin

i.e. echo "gem: -n/usr/local/bin" >> ~/.gemrc

IE echo "gem: -n/usr/local/bin" >> ~/.gemrc

or

或者

gem: --user-install -n~/bin

i.e. echo "gem: --user-install -n~/bin" >> ~/.gemrc

IE echo "gem: --user-install -n~/bin" >> ~/.gemrc

(Tip:You can also throw in --no-documentto skip generating Ruby developer documentation.)

提示:您也可以--no-document跳过生成 Ruby 开发人员文档。)

回答by Francisco Gonzalez Rull

In my case, I had to re-install Ruby using Brew. That seems to have solved the problem as I can install gems again.

就我而言,我不得不使用Brew重新安装 Ruby 。这似乎解决了问题,因为我可以再次安装 gems。

brew install ruby

After this, you need to log out and log back in, either graphically or just restarting your terminal.

在此之后,您需要注销并重新登录,以图形方式或仅重新启动终端。

回答by Shao Wenbin

That is because of the new security function of OS X "El Capitan". Try adding --user-installinstead of using sudo:

这是因为 OS X“El Capitan”的新安全功能。尝试添加--user-install而不是使用 sudo:

$ gem install *** --user-install

For example, if you want to install fake3 just use:

例如,如果你想安装 fake3 只需使用:

$ gem install fake3 --user-install

回答by Femina Brahmbhatt

sudo gem install -n /usr/local/bin cocoapods

Try this. It will definately work.

尝试这个。它肯定会起作用。

回答by astrasleepz

You have to update Xcode to the newest one (v7.0.1) and everything will work as normal.

您必须将 Xcode 更新到最新版本 (v7.0.1),一切都会正常进行。

If after you install the newest Xcode and still doesn't work try to install gem in this way:

如果在安装最新的 Xcode 后仍然无法正常工作,请尝试以这种方式安装 gem:

sudo gem install -n /usr/local/bin GEM_NAME_HERE

For example:

例如:

sudo gem install -n /usr/local/bin fakes3
sudo gem install -n /usr/local/bin compass
sudo gem install -n /usr/local/bin susy

回答by foobar

Looks like when upgrading to OS X El Capitain, the /usr/local directory is modified in multiple ways :

看起来升级到 OS X El Capitain 时,/usr/local 目录以多种方式修改:

  1. user permissions are reset (this is also a problem for people using Homebrew)
  2. binaries and symlinks might have been deleted or altered
  1. 用户权限被重置(这对于使用 Homebrew 的人来说也是一个问题)
  2. 二进制文件和符号链接可能已被删除或更改

[Edit] There's also a preliminary thing to do : upgrade Xcode...

[编辑] 还有一个初步的事情要做:升级 Xcode...

Solution for #1 :

#1 的解决方案:

$ sudo chown -R $(whoami):admin /usr/local

This will fix permissions on the /usr/localdirectory which will then help both gem installand brew install|link|...commands working properly.

这将修复/usr/local目录的权限,这将有助于命令gem installbrew install|link|...命令正常工作。

Solution to #2 :

#2 的解决方案:

Ruby based issues

基于 Ruby 的问题

Make sure you have fixed the permissions of the /usr/localdirectory (see #1 above)

确保您已修复/usr/local目录的权限(请参阅上面的 #1)

First try to reinstall your gem using :

首先尝试使用以下命令重新安装您的 gem:

sudo gem install <gemname>

Note that it will install the latest version of the specified gem.

请注意,它将安装指定 gem 的最新版本。

If you don't want to face backward-compatibility issues, I suggest that you first determine which version of which gem you want to get and then reinstall it with the -v version. See an exemple below to make sure that the system won't get a new version of capistrano.

如果你不想面对向后兼容的问题,我建议你首先确定你想要获得哪个 gem 的哪个版本,然后用-v version. 请参阅下面的示例以确保系统不会获得新版本的 capistrano。

$ gem list | grep capistrano
capistrano (3.4.0, 3.2.1, 2.14.2)
$ sudo gem install capistrano -v 3.4.0

Brew based issues

基于 Brew 的问题

Update brew and upgrade your formulas

更新 brew 并升级您的公式

$ brew update
$ brew upgrade

You might also need to re-link some of them manually

您可能还需要手动重新链接其中的一些

$ brew link <formula>

回答by emchateau

As it have been said, the issue comes from a security function of Mac OSX since "El Capitan".

如前所述,该问题来自自“El Capitan”以来 Mac OSX 的安全功能。

Using the default system Ruby, the install process happens in the /Library/Ruby/Gems/2.0.0directory which is not available to the user and gives the error.

使用默认系统 Ruby,安装过程发生在/Library/Ruby/Gems/2.0.0用户不可用的目录中并给出错误。

You can have a look to your Ruby environments parameters with the command

您可以使用以下命令查看 Ruby 环境参数

$ gem env

There is an INSTALLATION DIRECTORY and a USER INSTALLATION DIRECTORY. To use the user installation directory instead of the default installation directory, you can use --user-installparameter instead as using sudowhich is never a recommanded way of doing.

有一个安装目录和一个用户安装目录。要使用用户安装目录而不是默认安装目录,您可以使用--user-install参数代替,因为使用sudo这绝不是推荐的做法。

$ gem install myGemName --user-install

There should not be any rights issue anymore in the process. The gems are then installed in the user directory?: ~/.gem/Ruby/2.0.0/bin

在此过程中不应再有任何供股。然后将 gem 安装在用户目录中?:~/.gem/Ruby/2.0.0/bin

But to make the installed gems available, this directory should be available in your path. According to the Ruby's faq, you can add the following line to your ~/.bash_profileor ~/.bashrc

但是为了使安装的 gems 可用,这个目录应该在你的路径中可用。根据Ruby 的 faq,您可以将以下行添加到您的~/.bash_profile~/.bashrc

if which ruby >/dev/null && which gem >/dev/null; then
    PATH="$(ruby -rubygems -e 'puts Gem.user_dir')/bin:$PATH"
fi

Then close and reload your terminal or reload your .bash_profileor .bashrc(. ~/.bash_profile)

然后关闭并重新加载您的终端或重新加载您的.bash_profile.bashrc( . ~/.bash_profile)

回答by Anirban Nandi 'Joy'

If the gem you are trying to install requires xml libraries, then try this:

如果您尝试安装的 gem 需要 xml 库,请尝试以下操作:

sudo gem install -n /usr/local/bin  <gem_name> -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/

Specifically, I ran into a problem while installing the nokogiri gem v 1.6.8 on OS X El Capitan

具体来说,我在 OS X El Capitan 上安装 nokogiri gem v 1.6.8 时遇到了问题

and this finally worked for me:

这最终对我有用:

sudo gem install -n /usr/local/bin  nokogiri -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/

To make sure you have libxml2 and libxslt installed, you can do:

要确保安装了 libxml2 和 libxslt,您可以执行以下操作:

brew install libxml2 libxslt
brew install libiconv

and then check to make sure you have xcode command line tools installed:

然后检查以确保您安装了 xcode 命令行工具:

xcode-select --install 

should return this error:

应该返回这个错误:

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

回答by jbalesteri

This is the solution that I have used:

这是我使用的解决方案:

Note: this fix is for compass as I wrote it on another SO question, but I have used the same process to restore functionality to all terminal processes, obviously the gems you are installing are different, but the process is the same.

注意:此修复程序适用于我在另一个 SO 问题上写的指南针,但我使用相同的过程来恢复所有终端进程的功能,显然您安装的 gem 不同,但过程是相同的。

I had the same issue. It is due to Apple implementing System Integrity Protection (SIP). You have to first disable that...

我遇到过同样的问题。这是由于 Apple 实施了系统完整性保护 (SIP)。你必须先禁用它...

Reboot in recovery mode:

以恢复模式重新启动:

Reboot and hold Command + Runtil you see the apple logo.

重新启动并按住Command + R直到您看到苹果徽标。

Once booted select Utilities > Terminalfrom top bar.

启动后,从顶部栏中选择实用程序 > 终端

type: csrutil disable

类型: csrutil disable

then type: reboot

然后输入: reboot

Once rebooted

一旦重新启动

Open terminal back up and enter the commands:

打开终端备份并输入命令:

sudo gem uninstall bundler

sudo gem uninstall bundler

sudo gem install bundler

sudo gem install bundler

sudo gem install compass

sudo gem install compass

sudo gem install sass

sudo gem install sass

sudo gem update --system

sudo gem update --system

The the individual gems that failed need to be fixed, so for each do the following:

需要修复失败的单个宝石,因此对每个宝石执行以下操作:

On my machine this was the first dependency not working so I listed it:

在我的机器上,这是第一个不工作的依赖项,所以我列出了它

sudo gem pristine ffi --version 1.9.3

sudo gem pristine ffi --version 1.9.3

Proceed through the list of gems that need to be repaired. In all you are looking at about 10 minutes to fix it, but you will have terminal commands for compass working.

继续浏览需要修复的宝石列表。您总共需要大约 10 分钟的时间来修复它,但是您将拥有指南针工作的终端命令。

Screenshot

截屏

回答by kkelleey

Reinstalling RVM worked for me, but I had to reinstall all of my gems afterward:

重新安装 RVM 对我有用,但之后我不得不重新安装所有 gem:

rvm implode
\curl -sSL https://get.rvm.io | bash -s stable --ruby
rvm reload