且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么我会收到“权限被拒绝"?安装 gem 时出错?

更新时间:2022-11-30 15:56:19

您的 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 安装到您自己的主目录中,在那里您将能够自动安装 Ruby 和 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.