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 access nodejs and npm accessible as root as well. For that I tried adding in /root/.bashrc the following content :


After that I tried node and npm, 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... :-(


/home/deploy/nodejs/bin/npm: 1: /home/deploy/nodejs/bin/npm: dirname: not found
/home/deploy/nodejs/bin/npm: 2: exec: /node: not found

1) You're overwriting the path which breaks a lot of your system. The correct line would be:


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)

| improve this answer | |
  • Okay..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. – We are Borg Apr 22 '16 at 9:52
  • Oh, 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 – momar Apr 22 '16 at 10:03
  • Your 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. :-) – We are Borg Apr 22 '16 at 11:02
  • 1
    The /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. – momar Apr 22 '16 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.