ruby 安装 gem 失败,权限错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19579392/
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
Installing gem fails with permissions error
提问by Aniruddha
I updated my Mac OS to 10.9 Mavericks yesterday. My current Ruby version shows as
我昨天将我的 Mac OS 更新到 10.9 Mavericks。我当前的 Ruby 版本显示为
ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]
ruby 2.0.0p247 (2013-06-27 修订版 41674) [universal.x86_64-darwin13]
I got Rails installed on my machine and when I try to install gems I get the following message:
我在我的机器上安装了 Rails,当我尝试安装 gems 时,我收到以下消息:
Fetching: eventmachine-1.0.3.gem (100%) ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
I am trying all this in my home directory. Any suggestions?
我正在我的主目录中尝试所有这些。有什么建议?
回答by Stuart Nelson
Use a Ruby version manager, like RVMor rbenv.
I can't speak for rbenv, but RVM prepends a Ruby version-specific binto your PATHthat you have access to, so you don't have to use sudo(which is how you could install gems in your current situation, but is highly discouraged).
我不能说 rbenv,但是 RVM 预先准备了一个特定bin于您PATH可以访问的 Ruby 版本,因此您不必使用sudo(这是您在当前情况下安装 gems 的方式,但非常不鼓励) .
rbenv similarly prepends to your $PATH, but it uses a shim.
rbenv 同样预先添加到您的$PATH,但它使用垫片。
回答by Kingsley Ijomah
When I had this same error it was because I did not have a Ruby version manager installed, it defaulted to the Ruby version that came shipped with my computer which is owned root.
当我遇到同样的错误时,这是因为我没有安装 Ruby 版本管理器,它默认为我的计算机附带的 Ruby 版本,该版本拥有 root 权限。
Since it is a very bad idea to use sudoto install gems, I installed RVM with Ruby 2.1.2
由于sudo用于安装 gems是一个非常糟糕的主意,因此我使用 Ruby 2.1.2 安装了 RVM
\curl -sSL https://get.rvm.io | bash -s stable --ruby=2.1.2
then made sure that it was being used as the default by running
然后通过运行确保它被用作默认值
rvm use ruby-2.1.2
RVM creates a new location to store your Ruby and gems with your user permissions so you don't have to use sudoor get a permissions error. The new gem location is:
RVM 创建一个新位置来存储具有您用户权限的 Ruby 和 gem,这样您就不必使用sudo或收到权限错误。新的宝石位置是:
~/.rvm/gems
Then carry on as you were...
然后像你一样继续......
gem install ....
回答by Jonathan Lin
I do not have RVM installed. I got this error because I installed rbenv but did not run rbenv inityet.
我没有安装 RVM。我收到此错误是因为我安装了 rbenv 但尚未运行rbenv init。
After I inserted the contents from the command rbenv initinto .bash_profile, gem installworks as expected.
在我将命令中的内容rbenv init插入 .bash_profile 后,gem install按预期工作。
I also happened to set rbenv global <ruby-version>to a downloaded Ruby version first.
我也碰巧先设置rbenv global <ruby-version>为下载的 Ruby 版本。
回答by Jonathan Lin
Just like to say to you all after wasting a good hour or more on trying to install RubyGems... to rubygems-2.4.5'sudo'got me through! It works a treat...
就像在尝试安装 RubyGems 上浪费了一个多小时或更长时间之后对大家说的……到rubygems-2.4.5 'sudo'让我通过了!它是一种享受......

