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

2 Answers 2


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)

  • 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. Apr 22, 2016 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, 2016 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. :-) Apr 22, 2016 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, 2016 at 11:06

What I did was the following:

  1. download the correct version (in my case for ARMv7 for Raspberry Pi 3b) from NodeJS site
  2. unpack in /opt/node (using xz -d and tar xf )
  3. this usually leaves you with everything in a sub directory, so I moved everything : mv node-v14.15.4-linux-armv7l/* .
  4. make soft links to the /usr/bin for node, npm and npx
    root@fileserver:/opt/node# ln -s /opt/node/bin/npx /usr/bin/npx
    root@fileserver:/opt/node# ln -s /opt/node/bin/node /usr/bin/node
    root@fileserver:/opt/node# ln -s /opt/node/bin/npm /usr/bin/npm 

then everything works like a charm. notice you might have to alter the rights using chmod to allow access by other users.

For a user based solution have a look at https://github.com/nodejs/help/wiki/Installation#how-to-install-nodejs-via-binary-archive-on-linux

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .