Can’t use NVM from root (or sudo)

The below list of commands (source: digitalocean) seems to fix the problem

WARNING!!!! In some circumstances, these commands can break your system! Make sure you know what do these command do!!! related

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.

Hope this helps!

Leave a Comment