Skip to content

Instantly share code, notes, and snippets.

@itsmepetrov
Created November 12, 2015 13:51
Show Gist options
  • Save itsmepetrov/ff66e83428abe601a141 to your computer and use it in GitHub Desktop.
Save itsmepetrov/ff66e83428abe601a141 to your computer and use it in GitHub Desktop.
Fix NVM to use from root (or sudo)
# StackOverflow: http://stackoverflow.com/questions/21215059/cant-use-nvm-from-root-or-sudo
# Source: https://www.digitalocean.com/community/tutorials/how-to-install-node-js-with-nvm-node-version-manager-on-a-vps
# The below command seems to fix the problem
n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local
# The above command is a bit complicated, but all it's doing is copying whatever version of node
# you have active via nvm into the /usr/local/ directory (where user installed global files should
# live on a linux VPS) and setting the permissions so that all users can access them.
@Swarag-N
Copy link

it did work for me, thanks.

@mbaev
Copy link

mbaev commented May 8, 2020

@itsmepetrov

@logesh14 no, it's not a spam, it helped me when I was working on Ubuntu. It doesn't change user privilege and the command is quite clear to understand.

If the command will run on a machine which haven't node installed, then it will cause changing of permissions to 755 for all files under /bin.
The snipped looks ok for people who understand what really happens here, but it quite dangerous for others. Especially the last command. It's really may break an os =)

It's better to add checking of the node existence on machine:

which node && n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment