Ruby-on-rails 无法安装 RVM。/usr/local/rvm 中的权限被拒绝

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

Cannot install RVM . Permission denied in /usr/local/rvm

ruby-on-railsrvm

提问by Yash Desai

Based on my previous thread : RVM installed by Ruby not working?where i had installed RVM using the root user, I then had to entirely remove the RVM install and now i am installing as a user.

基于我之前的线程:Ruby 安装的 RVM 不起作用?我使用 root 用户安装了 RVM,然后我不得不完全删除 RVM 安装,现在我以用户身份安装。

So i did :

所以我做了 :

  1. Create a new user by doing : useradd newuser
  2. Follow the instructions on the RVM website and execute the command : bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head)
  1. 通过执行以下操作创建新用户:useradd newuser
  2. 按照 RVM 网站上的说明执行命令: bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head)

Now, i get the error : mkdir: cannot create directory `/usr/local/rvm': Permission denied

现在,我收到错误:mkdir:无法创建目录`/usr/local/rvm':权限被拒绝

The new user i created does not have access to this directory. I manually tried creating the folder but the same error. Please help.

我创建的新用户无权访问此目录。我手动尝试创建文件夹但同样的错误。请帮忙。

EDIT : The original problem occured because i did not restart the terminal and it was still using the old settings.

编辑:最初的问题是因为我没有重新启动终端并且它仍在使用旧设置。

Now, I got a new problem : After installing RVM, i cannot run it and it gives me an error : rvm command not found.

现在,我遇到了一个新问题:安装 RVM 后,我无法运行它,它给我一个错误:找不到 rvm 命令。

Here is the output of my ~/.bash_profile

这是我的 ~/.bash_profile 的输出

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"  # This loads RVM into a shell session.

And here is output from ~/.bashrc file

这是 ~/.bashrc 文件的输出

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific aliases and functions
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"  # This loads RVM into a shell session.

采纳答案by the Tin Man

RVM is easy to install, but you are making it harder by trying to mix and match installation types. You do NOT need to create a new user. When run, RVM will create a directory in your home directory: ~/.rvm, and install everything inside it. That means you will have all the correct permissions. You do NOT need to be running as root, you do NOT need to use sudo. I'd recommend closing all your command-lines and open one fresh and start at your home directory. If you are running as root, log out, and log back in to your normal account. For a single-user install you do NOT need to be root.

RVM 很容易安装,但是通过尝试混合和匹配安装类型会使安装变得更加困难。您不需要创建新用户。运行时,RVM 将在您的主目录中创建一个目录:~/.rvm,并将所有内容安装在其中。这意味着您将拥有所有正确的权限。您不需要以 root 身份运行,也不需要使用 sudo。我建议关闭所有命令行并重新打开一个并从您的主目录开始。如果您以 root 身份运行,请注销,然后重新登录到您的普通帐户。对于单用户安装,您不需要是 root。

For a single user, using RVM as their Ruby sandbox, use the single-user installation docs. Follow ALLthe instructions on that page, INCLUDINGthe "Post Install" section.

对于使用 RVM 作为其 Ruby 沙箱的单用户,请使用单用户安装文档。按照该页面上的所有说明进行操作,包括“安装后”部分。

Close your terminal window, and reopen it. If you have correctly followed the instructions above, typing rvm infoshould spit out a template of what is to come once you install a Ruby instance. If you see nothing output, or get an error, then retrace your steps in the "Post Install" section, and go through the "Troubleshooting" section. Most of the problems people have occur because they didn't bother to read the directions.

关闭终端窗口,然后重新打开它。如果您正确地遵循了上面的说明,rvm info那么在安装 Ruby 实例后,输入应该会输出一个模板。如果您没有看到任何输出,或者出现错误,请在“安装后”部分中回溯您的步骤,并通过“疑难解答”部分。人们之所以会出现大多数问题,是因为他们没有费心阅读说明。

Once RVM is installed, type rvm notesand read what dependencies you need to install. If you do not add those files your Rubies installed will be missing functionality. They will work, but some of the creature comforts you'll hear about won't work and you will wonder why.

安装 RVM 后,键入rvm notes并阅读您需要安装的依赖项。如果您不添加这些文件,您安装的 Ruby 将缺少功能。它们会起作用,但是您会听到的一些物质享受不起作用,您会想知道为什么。

After installing the dependencies you should be in good shape to install Rubies. Type rvm list knownfor all the Rubies RVM can install. If you want 1.8.7 type rvm install 1.8.7, and, similarly, rvm install 1.9.2for Ruby 1.9.2. If you want a particular revision you can add that, based on the ones in the list.

安装依赖项后,您应该可以安装 Ruby 了。类型rvm list known为所有 Ruby RVM 可以安装。如果你想要 1.8.7 类型rvm install 1.8.7,同样地,rvm install 1.9.2对于 Ruby 1.9.2。如果您想要一个特定的修订,您可以根据列表中的修订添加该修订。

It's important to periodically update RVM using rvm get head. That will add features, fix bugs, and tell RVM about new versions of Ruby it can install if you request.

使用rvm get head. 这将添加功能,修复错误,并告诉 RVM 可以安装的 Ruby 新版本(如果您要求的话)。

After installing a Ruby, type rvm listand it should show up in the list, looking something like this:

安装 Ruby 后,键入rvm list它应该会显示在列表中,如下所示:

rvm rubies

   ruby-1.8.7-p334 [ x86_64 ]
   ruby-1.9.2-p180 [ x86_64 ]

Type rvm use 1.9.2 --defaultto set a default Ruby that will be sticky between logins. Use the version of whatever Ruby you want to default to if 1.9.2 doesn't float your boat. Once you've defined a default it should look something like:

键入rvm use 1.9.2 --default以设置将在登录之间保持粘性的默认 Ruby。如果 1.9.2 不能让您的船漂浮,请使用您想要默认使用的任何 Ruby 版本。定义默认值后,它应该类似于:

rvm rubies

   ruby-1.8.7-p334 [ x86_64 ]
=> ruby-1.9.2-p180 [ x86_64 ]

Before you begin installing gems into a RVM-managed Ruby, read "RVM and RubyGems ", in particular the part that says "DO NOT use sudo... ". I repeat. Do NOT use sudo to install any gems, in spite of what some blog or web page says. RVM's author knows better when it comes to working with RVM controlled Rubies. That is another mistake people use with RVM, again as a result of not reading the directions.

在开始将 gems 安装到 RVM 管理的 Ruby 之前,请阅读“RVM 和 RubyGems”,特别是“不要使用 sudo...”的部分。我重复。不要使用 sudo 安装任何 gems,不管一些博客或网页怎么说。RVM 的作者在使用 RVM 控制的 Ruby 时更了解。这是人们在 RVM 中使用的另一个错误,同样是由于没有阅读说明。

On Mac OS, you'll need the latest version of XCode for your OS. Do NOT use the XCode that came with Snow Leopard on the DVD. It is buggy. Download and install a new version from Apple's Developer site. It's a free download requiring a free registration. It's a big file, approximately 8GB, so you'll want to start it and walk away. Install XCode, and you should be ready to have RVM install Rubies.

在 Mac OS 上,您的操作系统需要最新版本的 XCode。不要使用 DVD 中 Snow Leopard 附带的 XCode。这是越野车。从Apple 的开发人员网站下载并安装新版本。这是一个需要免费注册的免费下载。这是一个大约 8GB 的​​大文件,因此您需要启动它然后走开。安装 XCode,您应该准备好让 RVM 安装 Ruby。

Finally, RVM installs easily, as will the Rubies you ask it to install. I have it on about four or five different machines and VMs on Mac OS, Ubuntu and CentOS. It takes me about a minute to install it and another minute to configure it and start installing a new Ruby. It really is that easy.

最后,RVM 很容易安装,就像您要求它安装的 Ruby 一样。我在 Mac OS、Ubuntu 和 CentOS 上的大约四到五台不同的机器和 VM 上安装了它。我花了大约一分钟来安装它,再花一分钟来配置它并开始安装一个新的 Ruby。它真的很容易。

回答by tristan

mkdir: cannot create directory `/usr/local/rvm': Permission denied

mkdir: 无法创建目录 `/usr/local/rvm': 权限被拒绝

If you've run the rvm installer as root previously, remove /usr/local/rvm and /etc/rvmrc.

如果您之前以 root 身份运行 rvm 安装程序,请删除 /usr/local/rvm 和 /etc/rvmrc。

回答by Nathan Ratcliff

I had the original issue reported in this question, "mkdir: cannot create directory `/usr/local/rvm': Permission denied" when trying to install rvm.

我在这个问题中报告了原始问题,“ mkdir:尝试安装 rvm 时无法创建目录`/usr/local/rvm':权限被拒绝”。

This is my scenario and how I solved it - maybe this will help others with this same issue.

这是我的场景以及我如何解决它 - 也许这会帮助其他人解决同样的问题。

I have Ubuntu 11.04 installed on a laptop, I only have 1 user, the one I created at install time, named nathan. When I would try to install rvm as nathan, the rvm installer saw me as root and kept trying to install rvm globally, but since I wasn't really root, it couldn't get access to create directories in /usr/local/rvm.

我在笔记本电脑上安装了 Ubuntu 11.04,我只有 1 个用户,这是我在安装时创建的,名为 nathan。当我尝试将 rvm 安装为 nathan 时,rvm 安装程序将我视为 root 并继续尝试全局安装 rvm,但由于我不是真正的 root,因此无法访问在 /usr/local/rvm 中创建目录.

I'm far from an expert with Ubuntu, so I'm sure there are easier/better ways to accomplish the things I did (and I would love to learn about them), but this worked for me:

我远非 Ubuntu 专家,所以我确信有更简单/更好的方法来完成我所做的事情(我很想了解它们),但这对我有用:

  1. I created a new user called rubydev
  2. I logged in as rubydev, opened a terminal and typed:

    rubydev~$ bash < <(curl -B http://rvm.beginrescueend.com/install/rvm)
    
  3. rvm installed correctly and I logged out of rubydev

  4. Signed back in as nathan, opened a terminal and typed "su" (you could do all this with sudo, I am lazy)
  5. After successfully getting root, I typed the following commands:

    root: /home/nathan# cp -R /home/rubydev/.rvm .
    
    root: /home/nathan# chown -R nathan .rvm
    
    root: /home/nathan# chgrp -R nathan .rvm
    
    root: /home/nathan# exit
    
    nathan~$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
    
    nathan~$ echo 'export rvm_path="/home/nathan/.rvm"' > ~/.rvmrc
    
    nathan~$ source .bash_profile
    
  6. At this point, rvm was correctly installed under my home directory. To verify I typed:

    nathan~$ type rvm | head -1
    rvm is a function (if you don't get this response, something else is wrong)
    
  7. Read the notes and installed any dependencies

    nathan~$ rvm notes
    
  8. I installed some rubies

    nathan~$ rvm install 1.8.7-head
    nathan~$ rvm install 1.9.2-head
    
  9. Verified install

        nathan~$ rvm list
    
        rvm rubies
            ruby-1.8.7-head [x86_64]
            ruby-1.9.2-head [x86_64]
    
        nathan~$ rvm use 1.9.2
        using /home/nathan/.rvm/gems/ruby-1.9.2-head
    
        nathan~$ rvm list
    
        rvm rubies
           ruby-1.8.7-head [x86_x64]
        => ruby-1.9.2-head [x86_x64]
    
  10. Finally, I edited the preferences on the terminal itself to ensure the "Run command as as login shell" under the "Title and Command" tab was checked. It seems .bash_profile isn't otherwise processed.

  11. I removed the rubydev user I created in step 1.

  1. 我创建了一个名为 ruby​​dev 的新用户
  2. 我以 ruby​​dev 身份登录,打开一个终端并输入:

    rubydev~$ bash < <(curl -B http://rvm.beginrescueend.com/install/rvm)
    
  3. rvm 安装正确,我退出了 ruby​​dev

  4. 以 nathan 的身份重新登录,打开一个终端并输入“su”(你可以用 sudo 完成所有这些,我很懒)
  5. 成功获得root后,我输入了以下命令:

    root: /home/nathan# cp -R /home/rubydev/.rvm .
    
    root: /home/nathan# chown -R nathan .rvm
    
    root: /home/nathan# chgrp -R nathan .rvm
    
    root: /home/nathan# exit
    
    nathan~$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
    
    nathan~$ echo 'export rvm_path="/home/nathan/.rvm"' > ~/.rvmrc
    
    nathan~$ source .bash_profile
    
  6. 至此,rvm已正确安装在我的主目录下。为了验证我输入:

    nathan~$ type rvm | head -1
    rvm is a function (if you don't get this response, something else is wrong)
    
  7. 阅读说明并安装任何依赖项

    nathan~$ rvm notes
    
  8. 我安装了一些红宝石

    nathan~$ rvm install 1.8.7-head
    nathan~$ rvm install 1.9.2-head
    
  9. 验证安装

        nathan~$ rvm list
    
        rvm rubies
            ruby-1.8.7-head [x86_64]
            ruby-1.9.2-head [x86_64]
    
        nathan~$ rvm use 1.9.2
        using /home/nathan/.rvm/gems/ruby-1.9.2-head
    
        nathan~$ rvm list
    
        rvm rubies
           ruby-1.8.7-head [x86_x64]
        => ruby-1.9.2-head [x86_x64]
    
  10. 最后,我编辑了终端本身的首选项,以确保选中“标题和命令”选项卡下的“将命令作为登录 shell 运行”。似乎 .bash_profile 没有以其他方式处理。

  11. 我删除了在步骤 1 中创建的 ruby​​dev 用户。

With all of that, I have a working rvm under Ubuntu 11.04 using my preferred username.

有了所有这些,我在 Ubuntu 11.04 下使用我的首选用户名有一个可以工作的 rvm。

回答by glebtv

I solved this by adding

我通过添加解决了这个问题

export rvm_path=~/.rvm

to ~/.bash_profile

到 ~/.bash_profile

回答by Scott Bartell

If you first installed RVM as root and then uninstalled it. And now you are trying to install it as a non sudo user and you're getting the following error:

如果您首先以 root 身份安装 RVM,然后将其卸载。现在您尝试以非 sudo 用户身份安装它,并且收到以下错误:

mkdir: cannot create directory `/usr/local/rvm': Permission denied

Make sure that you have logged out of the root session before trying to install under the user.

在尝试以用户身份进行安装之前,请确保您已注销 root 会话。

回答by Calin

For me running

为我跑步

__rvm_unload

__rvm_unload

Worked first, this was due to the fact that I had rvm installed as for multiuser.

首先工作,这是因为我为多用户安装了 rvm。

回答by Diego

I had the same issue. When I tried to create a gemset I would get a permission denied error. I just forgot to run the "rvm use 1.8.7" command first. After that I was able to create and use the gemset without any problems.

我遇到过同样的问题。当我尝试创建一个 gemset 时,我会收到一个权限被拒绝的错误。我只是忘了先运行“rvm use 1.8.7”命令。之后,我可以毫无问题地创建和使用 gemset。

回答by rogermushroom

If you installing RVM as a user then the RVM folder should be generated in your home directory:

如果您以用户身份安装 RVM,则应在您的主目录中生成 RVM 文件夹:

~/.rvm 

Where there should be no permissions problems at all.

根本不应该有权限问题。

I would suggest it is picking up some old config that is left over from your system installation.

我建议它选择一些从您的系统安装中遗留下来的旧配置。

Ensure there is no /etc/rvmrc or $HOME/.rvmrc file left over because it might be using previously initialised variables from these files to construct an incorrect installation path.

确保没有剩余的 /etc/rvmrc 或 $HOME/.rvmrc 文件,因为它可能正在使用这些文件中先前初始化的变量来构建不正确的安装路径。

if we look at this section of the bash script:

如果我们查看 bash 脚本的这一部分:

if [[ ${rvm_ignore_rvmrc:-0} -eq 0 ]]; then
  for file in /etc/rvmrc "$HOME/.rvmrc  " ; do
    if [[ -s "$file" ]] ; then
      source $file
    fi
  done
fi

It is trying to find one of these files, if it finds one if will run it possibly initialising rvm_path which will subsequently not be set as $HOME/.rvm by this command

它试图找到这些文件之一,如果它找到一个,如果它会运行它可能会初始化 rvm_path 它将随后不会被此命令设置为 $HOME/.rvm

rvm_path="${rvm_path:-"$HOME/.rvm"}"

回答by johananp

In lasts versions of rvm you need remove /etc/profile.d/ also.

在 rvm 的最新版本中,您还需要删除 /etc/profile.d/。

This happen often if you try to install as root and then try again as a regular user.

如果您尝试以 root 用户身份进行安装,然后以普通用户身份再次尝试,则经常会发生这种情况。

Hope this help.

希望这有帮助。

回答by kaineer

Look for file rvm.sh below /etc directory (It may be in /etc, or /etc/init.d). Also, try some grep rvm /etc -r, so you can find some files/lines which prevent you from installing rvm in your $HOME dir.

在 /etc 目录下查找文件 rvm.sh(它可能在 /etc 或 /etc/init.d 中)。另外,尝试一些 grep rvm /etc -r,这样您就可以找到一些文件/行,这些文件/行阻止您在 $HOME 目录中安装 rvm。