为什么我会收到“权限被拒绝"的提示?安装gem时出错? [英] Why do I get a "permission denied" error while installing a gem?

查看:94
本文介绍了为什么我会收到“权限被拒绝"的提示?安装gem时出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试安装Jekyll.运行gem install jekyll后,出现此错误:

I'm attempting to install Jekyll. After running gem install jekyll I get this error:

ERROR:  While executing gem ... (Errno::EACCES)
    Permission denied - /usr/local/lib/ruby/gems/2.0.0/gems/jekyll-1.0.3/CONTRIBUTING.md

我在运行gem list时看到已安装Jekyll,所以我感到非常困惑:

I can see that Jekyll is installed when I run gem list so I'm thoroughly confused:

*** LOCAL GEMS ***

bigdecimal (1.2.0)
classifier (1.3.3)
colorator (0.1)
commander (4.1.3)
directory_watcher (1.4.1)
fast-stemmer (1.0.2)
highline (1.6.19)
io-console (0.4.2)
jekyll (1.0.3)
json (1.7.7)
kramdown (1.0.2)
liquid (2.5.0)
maruku (0.6.1)
minitest (4.3.2)
posix-spawn (0.3.6)
psych (2.0.0)
pygments.rb (0.5.1)
rake (0.9.6)
rdoc (4.0.0)
rubygems-update (2.0.3)
safe_yaml (0.7.1)
syntax (1.0.0)
test-unit (2.0.0.0)
yajl-ruby (1.1.0)

过去我的用户路径存在很多问题,所以我想知道此错误是否与之有关?

I've had a lot of problems with my user paths in the past, so I'm wondering if this error could have something to do with that?

这是gem env的输出:

RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.3
  - RUBY VERSION: 2.0.0 (2013-02-24 patchlevel 0) [x86_64-darwin12.3.0]
  - INSTALLATION DIRECTORY: /usr/local/Cellar/ruby/2.0.0-p0/lib/ruby/gems/2.0.0
  - RUBY EXECUTABLE: /usr/local/Cellar/ruby/2.0.0-p0/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/local/Cellar/ruby/2.0.0-p0/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-12
  - GEM PATHS:
     - /usr/local/Cellar/ruby/2.0.0-p0/lib/ruby/gems/2.0.0
     - /Users/me/.gem/ruby/2.0.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/

这是我的".bash_profile":

Here is my ".bash_profile":

export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
PATH=$PATH:above/path/to/gems

source ~/.rvm/scripts/rvm

有人可以帮助我安装Jekyll,或者至少克服此权限错误吗?

Could somebody please help me get Jekyll installed, or at least get past this permissions error?

推荐答案

您的Ruby已安装在/usr/local/Cellar/ruby/...中.

Your Ruby is installed in /usr/local/Cellar/ruby/....

这是受限制的路径,仅当您以root用户身份运行或使用sudo使用提升的特权时才能写入.我不建议您以root用户身份运行,因为您不了解路径和权限的工作方式.您可以 使用sudo gem install jekyll,它将临时提升您的权限,为您的命令提供写入该目录所需的权限.

That is a restricted path and can only be written to when you use elevated privileges, either by running as root or by using sudo. I won't recommend you run things as root since you don't understand how paths and permissions work. You can use sudo gem install jekyll, which will temporarily elevate your permissions, giving your command the rights needed to write to that directory.

但是,我建议您认真考虑不要这样做,而应使用RVM将Ruby安装到您自己的主目录中,在该目录中您将能够自动安装Rubies和gems,而没有权限问题.请参阅"单用户安装"中的安装到本地RVM沙箱中的说明.

However, I'd recommend you give serious thought into NOT doing that, and instead use your RVM to install Ruby into your own home directory, where you'll automatically be able to install Rubies and gems without permission issues. See the directions for installing into a local RVM sandbox in "Single-User installations".

由于您的~/.bash_profile中包含RVM,但是它未显示在您的Gem环境列表中,我怀疑您未遵循正确安装RVM的指示,或者您未使用全部-重要命令:

Because you have RVM in your ~/.bash_profile, but it doesn't show up in your Gem environment listing, I suspect you either haven't followed the directions for installing RVM correctly, or you haven't used the all-important command:

rvm use 2.0.0 --default

配置默认的Ruby.

to configure a default Ruby.

对于大多数用户而言,单用户安装"是必经之路.如果必须在该配置中使用sudo,则说明您做错了什么.

For most users, the "Single-User installation" is the way to go. If you have to use sudo with that configuration you've done something wrong.

这篇关于为什么我会收到“权限被拒绝"的提示?安装gem时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆