Command not found when executing node.js n package on sudo
I have found solution which worked for me:
sudo -E env "PATH=$PATH" n stable
Found it here: https://stackoverflow.com/a/29400598/861615
Surprisingly, your npm
installation has the global prefix in a folder called npm
on your home directory, this means that any package installed with the -g
flag will install on this folder.
You can change this folder to any folder that is on the sudo
safe path following these steps:
Graphical way:
- Open a File Manager (a.k.a Nautilus).
- Navigate to your home folder.
- Press Ctrl+H to show hidden files.
- Open a file called
.npmrc
with your favorite text editor. Find a line on that file with this content:
prefix=/home/<your_username>/npm
- Replace
/home/<your_username>/npm
by a safe path (such as/usr/local/bin
). Once replaced it will look like this:
prefix=/usr/local/bin
- Save the file.
- Run again
sudo npm install n -g
Terminal way:
Run this command:
sed -i.bak "s%^prefix=.*$%prefix=/usr/local/bin%" ~/.npmrc
I know this is an Ubuntu forum, but I'm sure this will help someone with the same problem on the RHEL flavours who Googled to here like I did. Perhaps it also works in Ubuntu.
This is the approach:
ln -s /usr/local/bin/n /usr/bin/n