Cannot install RVM . Permission denied in /usr/loc

2019-02-01 21:20发布

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.

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 )

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

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.

Here is the output of my ~/.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

# 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.

12条回答
干净又极端
2楼-- · 2019-02-01 21:59

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.

查看更多
ら.Afraid
3楼-- · 2019-02-01 22:00

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.

查看更多
做个烂人
4楼-- · 2019-02-01 22:04

I had the original issue reported in this question, "mkdir: cannot create directory `/usr/local/rvm': Permission denied" when trying to install 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.

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:

  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.

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

查看更多
地球回转人心会变
5楼-- · 2019-02-01 22:08

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

~/.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.

if we look at this section of the bash script:

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="${rvm_path:-"$HOME/.rvm"}"
查看更多
乱世女痞
6楼-- · 2019-02-01 22:10

I solved this by adding

export rvm_path=~/.rvm

to ~/.bash_profile

查看更多
Emotional °昔
7楼-- · 2019-02-01 22:13

If you installed rvm as root and you are getting permission denied issues (maybe you are deploying with capistrano as a non root user) then you could try rvm fix-permissions after doing things like rvm install 2.2.2 as root and creating a gemset as root.

查看更多
登录 后发表回答