0
votes

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

1

1 Answers

2
votes

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