0

I just fired up a new EC2 instance on Amazon and I'm trying to install nvm. I tried running their install script with the NVM_DIR=... for a global install:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | NVM_DIR=/usr/local/nvm bash

but I get this error:

=> Downloading nvm from git to '/usr/local/nvm' => mkdir: cannot create directory ‘/usr/local/nvm’: Permission denied

I get this error with sudo as well. I also tried going into usr/local and making the nvm directory manually, but then i get other errors like this:

=> Cloning into '/usr/local/nvm'... /usr/local/nvm/.git: Permission denied

Does anyone know why this is happening? Is it a permissions thing on aws I am unfamiliar with?

Edit: using a much older version without the NVM_DIR stuff worked. I still want global access though, so this does not solve the problem

curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | sh

user137717
  • 2,005
  • 4
  • 25
  • 48

1 Answers1

2

Your normal user won’t have access to write to /usr/local, so you’ll need to run the install script as root/sudo.

Your curl command is fine to run as your user. In fact, it’s best to just curl the file to a local location before running it, so you can eyeball it -- unless you have reason to believe it is a very trustworthy script. So grab the install.sh script:

% curl -O https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh
% $EDITOR install.sh  # feel free to look it over

Then install it with sudo:

% sudo -i  # become root temporarily
# export NVM_DIR=/usr/local/nvm  # set the environment variable
# bash install.sh  # run installer as root
# exit
%

(There is a way to make the whole installation a one-liner, passing the environment variable through sudo, but I don't think it's necessary, and a little more complex, IMHO.)

Community
  • 1
  • 1
Micah Elliott
  • 9,600
  • 5
  • 51
  • 54
  • but why doesn't the script have access to write to usr/local when i run the curl command with sudo curl.... ? – user137717 Aug 14 '15 at 02:32
  • 1
    Because the second command, bash, after the pipe, is not sudo'd. You'd need the sudo on the bash part because it is what's running the install. But the above steps described did the trick, right? – Micah Elliott Aug 14 '15 at 03:06
  • tbh, I had hacked around the install before I saw this answer, but I really wanted to know why sudo curl... wasn't giving the script permission to create dirs and files. – user137717 Aug 14 '15 at 17:39