简体   繁体   English

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

[英]Cannot install RVM . Permission denied in /usr/local/rvm

Based on my previous thread : RVM installed by Ruby not working? 根据我之前的帖子: Ruby安装的RVM无法正常工作? 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. 我使用root用户安装RVM的地方,然后我必须完全删除RVM安装,现在我作为用户安装。

So i did : 所以我做了 :

  1. Create a new user by doing : useradd newuser 通过执行以下操作创建新用户:useradd newuser
  2. Follow the instructions on the RVM website and execute the command : bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head ) 按照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.

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。

RVM is easy to install, but you are making it harder by trying to mix and match installation types. RVM易于安装,但是通过尝试混合和匹配安装类型会使您变得更加困难。 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. 运行时,RVM将在您的主目录中创建一个目录: ~/.rvm ,并在其中安装所有内容。 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. 您不需要以root身份运行,也不需要使用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. 如果以root用户身份运行,请注销,然后重新登录普通帐户。 For a single-user install you do NOT need to be root. 对于单用户安装,您不需要是root用户。

For a single user, using RVM as their Ruby sandbox, use the single-user installation docs . 对于使用RVM作为其Ruby沙箱的单个用户 ,请使用单用户安装文档 Follow ALL the instructions on that page, INCLUDING the "Post Install" section. 按照该页面上的所有说明进行操作, 包括 “安装后”部分。

Close your terminal window, and reopen it. 关闭终端窗口,然后重新打开它。 If you have correctly followed the instructions above, typing rvm info should spit out a template of what is to come once you install a Ruby instance. 如果您已正确遵循上述说明,则键入rvm info应该在安装Ruby实例后吐出一个模板。 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. 人们出现的大多数问题都是因为他们没有费心去阅读指示。

Once RVM is installed, type rvm notes and read what dependencies you need to install. 安装RVM后,键入rvm notes并阅读需要安装的依赖项。 If you do not add those files your Rubies installed will be missing functionality. 如果您不添加这些文件,则安装的Rubies将缺少功能。 They will work, but some of the creature comforts you'll hear about won't work and you will wonder why. 它们会起作用,但是你会听到的一些生物舒适功能不起作用,你会想知道为什么。

After installing the dependencies you should be in good shape to install Rubies. 安装依赖项后,您应该处于良好状态以安装Rubies。 Type rvm list known for all the Rubies RVM can install. 键入rvm list known所有rvm list known RVM可以安装。 If you want 1.8.7 type rvm install 1.8.7 , and, similarly, rvm install 1.9.2 for Ruby 1.9.2. 如果你想要1.8.7类型的rvm install 1.8.7 ,同样地, rvm install 1.9.2 for Ruby 1.9.2。 If you want a particular revision you can add that, based on the ones in the list. 如果您需要特定修订,可以根据列表中的修订添加该修订。

It's important to periodically update RVM using rvm get head . 使用rvm get head定期更新RVM非常重要。 That will add features, fix bugs, and tell RVM about new versions of Ruby it can install if you request. 这将添加功能,修复错误,并告诉RVM如果您请求它可以安装的新版本的Ruby。

After installing a Ruby, type rvm list and 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 --default to set a default Ruby that will be sticky between logins. 键入rvm use 1.9.2 --default设置一个默认的Ruby,它将在登录之间粘贴。 Use the version of whatever Ruby you want to default to if 1.9.2 doesn't float your boat. 如果1.9.2没有漂浮您的船,请使用您想要默认的任何Ruby的版本。 Once you've defined a default it should look something like: 一旦定义了默认值,它应该类似于:

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... ". 在开始将Gems安装到RVM管理的Ruby之前,请阅读“RVM和RubyGems” ,特别是“不要使用sudo ...”的部分。 I repeat. 我重复。 Do NOT use sudo to install any gems, in spite of what some blog or web page says. 尽管某些博客或网页上写道,但不要使用sudo来安装任何宝石。 RVM's author knows better when it comes to working with RVM controlled Rubies. 在使用RVM控制的Rubies时,RVM的作者更清楚。 That is another mistake people use with RVM, again as a result of not reading the directions. 这是人们使用RVM的另一个错误,再次是由于没有阅读指示。

On Mac OS, you'll need the latest version of XCode for your OS. 在Mac OS上,您需要为您的操作系统提供最新版本的XCode。 Do NOT use the XCode that came with Snow Leopard on the DVD. 请勿在DVD上使用Snow Leopard附带的XCode。 It is buggy. 它是马车。 Download and install a new version from Apple's Developer site . Apple的开发者网站下载并安装新版本。 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. 这是一个大文件,大约8GB,所以你想要启动它并走开。 Install XCode, and you should be ready to have RVM install Rubies. 安装XCode,您应该已准备好让RVM安装Rubies。

Finally, RVM installs easily, as will the Rubies you ask it to install. 最后,RVM很容易安装,你要求它安装的Rubies也是如此。 I have it on about four or five different machines and VMs on Mac OS, Ubuntu and CentOS. 我在Mac OS,Ubuntu和CentOS上大约有四五台不同的机器和虚拟机。 It takes me about a minute to install it and another minute to configure it and start installing a new Ruby. 安装它需要大约一分钟,配置它并开始安装新的Ruby需要一分钟。 It really is that easy. 它真的很容易。

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':Permission denied ”。

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. 我在笔记本电脑上安装了Ubuntu 11.04,我只有1个用户,我在安装时创建的用户名为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. 当我尝试将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 我创建了一个名为rubydev的新用户
  2. I logged in as rubydev, opened a terminal and typed: 我以rubydev身份登录,打开终端并输入:

     rubydev~$ bash < <(curl -B http://rvm.beginrescueend.com/install/rvm) 
  3. rvm installed correctly and I logged out of rubydev rvm安装正确,我退出rubydev

  4. Signed back in as nathan, opened a terminal and typed "su" (you could do all this with sudo, I am lazy) 作为nathan回来,打开一个终端并键入“su”(你可以用sudo完成所有这些,我很懒)
  5. After successfully getting root, I typed the following commands: 成功获得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. At this point, rvm was correctly installed under my home directory. 此时,rvm已正确安装在我的主目录下。 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. 最后,我编辑了终端本身的首选项,以确保选中“标题和命令”选项卡下的“运行命令和登录shell”。 It seems .bash_profile isn't otherwise processed. 似乎.bash_profile没有以其他方式处理。

  11. I removed the rubydev user I created in step 1. 我删除了在步骤1中创建的rubydev用户。

With all of that, I have a working rvm under Ubuntu 11.04 using my preferred username. 有了这些,我使用我的首选用户名在Ubuntu 11.04下有一个工作rvm。

If you first installed RVM as root and then uninstalled it. 如果您首先以root用户身份安装RVM,然后将其卸载。 And now you are trying to install it as a non sudo user and you're getting the following error: 现在您尝试将其安装为非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. 在尝试在用户下安装之前,请确保已注销根会话。

I solved this by adding 我通过添加来解决这个问题

export rvm_path=~/.rvm

to ~/.bash_profile 到〜/ .bash_profile

For me running 对我来说跑步

__rvm_unload

Worked first, this was due to the fact that I had rvm installed as for multiuser. 首先工作,这是因为我已经为多用户安装了rvm。

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"}"

I had the same issue. 我遇到过同样的问题。 When I tried to create a gemset I would get a permission denied error. 当我尝试创建gemset时,我会收到权限被拒绝错误。 I just forgot to run the "rvm use 1.8.7" command first. 我忘了先运行“rvm use 1.8.7”命令。 After that I was able to create and use the gemset without any problems. 之后我能够毫无问题地创建和使用gemset。

In lasts versions of rvm you need remove /etc/profile.d/ also. 在rstm的持续版本中,您还需要删除/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. 希望这有帮助。

Look for file rvm.sh below /etc directory (It may be in /etc, or /etc/init.d). 在/ etc目录下面查找文件rvm.sh(可能在/ etc或/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. 另外,尝试一些grep rvm / etc -r,这样你就可以找到一些阻止你在$ HOME目录中安装rvm的文件/行。

如果您以root身份安装了rvm并且您正在获得权限被拒绝的问题(可能您使用capistrano作为非root用户进行部署),那么您可以在执行rvm install 2.2.2之后尝试使用rvm fix-permissions作为root并创建gemset作为根。

Scott Bartell's solution worked for me. Scott Bartell的解决方案对我有用。 i am on a Digital Ocean premade image, where they had already setup rvm as root. 我正在使用数字海洋预制图像,他们已经将rvm设置为root。 1. deleted /etc/rvmrc . 1.删​​除/ etc / rvmrc。 2. added export rvm_path=~/.rvm to ~/.bash_profile 3. logged out of ssh session to virtual machine 4. logged back in and presto! 2.将导出rvm_path =〜/ .rvm添加到〜/ .bash_profile 3.从ssh会话中注销到虚拟机4.重新登录并执行!

would have commented but rep is 3 points too low :) 本来会评论,但代表是3分太低了:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM