Debian : Setting path for Node with root accessible globally
1) You're overwriting the path which breaks a lot of your system. The correct line would be:
PATH="$PATH:/home/deploy/nodejs/bin"
With that, you're appending something to PATH, instead of overriding it. Also, the PATH consists of directories (and not files), and /usr/bin
should be already in it, rendering the first part useless.
2) "Did you try turning it off and on again?" - the .bashrc
is only loaded on login, or when using source ~/.bashrc
. If you want to change the path system-wide, you should do so in /etc/profile
.
3) Also, make sure that there is a /home/deploy/nodejs/bin/node
file, and that it's executable (should definitely be the case if you installed it correctly, but you can run chmod a+x /home/deploy/nodejs/bin/node /home/deploy/nodejs/bin/npm
to be extra-sure)
Related videos on Youtube
We are Borg
Working in Pune,India. Open to meet new people, attend conferences, good talks. For followup on any answer or any doubt about posts on SO, email at kernelfreak[at]gmail.com :-)
Updated on September 18, 2022Comments
-
We are Borg over 1 year
I have downloaded
NodeJS
setup and have it inside at/home/deploy/nodejs
. I am trying to set its path, but it's not working out. I am logged in as root, and I would like to accessnodejs
andnpm
accessible as root as well. For that I tried adding in/root/.bashrc
the following content :PATH=/usr/bin/node:/home/deploy/nodejs/bin/ PATH=/usr/bin/npm:/home/deploy/nodejs/bin/
After that I tried
node
andnpm
, but none of them worked. What am I doing wrong?The files in
/home/deploy/nodejs/bin
are node, node_modules and npm. I tried the .deb installer, but that is not installing npm, only nodejs, so I have to do all this... :-(Update
npm /home/deploy/nodejs/bin/npm: 1: /home/deploy/nodejs/bin/npm: dirname: not found /home/deploy/nodejs/bin/npm: 2: exec: /node: not found
-
We are Borg about 8 yearsOkay..When I gave source ~/.bashrc, then other commands like ls, nano, etc have stopped working in that terminal, but when I opened a new ssh connection, then it worked. But npm command is still not working. I am adding error log for npm in main post.
-
momar about 8 yearsOh, I just see that you're actually overwriting the path and therefore all information about where ls, nano and so on are located! I updated my answer :D
-
We are Borg about 8 yearsYour command in 1st worked. Thank you very much. :-) Can you also tell me how I can add it in /etc/profile, just for information. Thank you. :-)
-
momar about 8 yearsThe
/etc/profile
is pretty much the same as the~/.bashrc
, just for all users. This means, you can just add the same line at the very bottom of this file.