390

I installed nodejs on ubuntu from instructions given here

When I write node --version in the terminal I see this :
-bash: /usr/sbin/node: No such file or directory

I can see node in the /usr/sbin/ directory, though.

Writing npm --version shows 1.3.5
Writing nodejs --version shows v0.10.15

Also, I can see node in the /usr/bin/ directory.

So, how do I get node working?

Also, If I use zsh instead of bash, then node command works.

12
  • 1
    If "you see node in /usr/bin/", then what is the output of ls -l /usr/bin/node?
    – randunel
    Aug 8, 2013 at 15:51
  • 1
    @randunel I got this output lrwxrwxrwx 1 root root 22 Jan 1 2013 /usr/bin/node -> /etc/alternatives/node
    – Jatin
    Aug 8, 2013 at 16:00
  • Did you make any changes to shell rc?
    – randunel
    Aug 8, 2013 at 16:13
  • This looks like a shell problem after your edit, what does export | grep PATH output when not using zsh? (it should print /usr/bin among other things)
    – randunel
    Aug 8, 2013 at 16:17
  • 1
    solution + explanation here: stackoverflow.com/questions/21168141/…
    – throbi
    Apr 15, 2016 at 10:08

22 Answers 22

613

You need to manually create a symlink /usr/bin/node. Shortcut for bash compatible shells:

sudo ln -s `which nodejs` /usr/bin/node

Or if you use non-standard shells, just hardcode the path you find with which nodejs:

sudo ln -s /usr/bin/nodejs /usr/bin/node

Later edit

I found this explanation in the link you posted

There is a naming conflict with the node package (Amateur Packet Radio Node Program), and the nodejs binary has been renamed from node to nodejs. You'll need to symlink /usr/bin/node to /usr/bin/nodejs or you could uninstall the Amateur Packet Radio Node Program to avoid that conflict.

Later later edit

It's been a while since I answered this. Although the solution I posted up here worked for me several times, users have reported a few more solutions within the comments:

From @user229115

sudo update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10

From AskUbuntu (user leftium)

sudo apt-get --purge remove node
sudo apt-get --purge remove nodejs
sudo apt-get install nodejs
10
  • okay! Although, if I use zsh, then the node command works.
    – Jatin
    Aug 8, 2013 at 16:04
  • 2
    Also, how do I uninstall the Amateur Packet Radio Node program? I tried sudo apt-get remove node but it says Package node is not installed, so not removed
    – Jatin
    Aug 8, 2013 at 16:06
  • You don't need to uninstall it, after your comments, this looks like a shell problem, not a node package problem.
    – randunel
    Aug 8, 2013 at 16:14
  • @randunel's answer did not work for me as /usr/bin/env node would not work. @BennyMcBenBen's solution did work
    – francoisrv
    May 27, 2014 at 14:36
  • 2
    @Tino's answer is the right one, see the nodejs-legacy package's description. The answer linked by @BennyMcBenBen has been updated with similar instructions too.
    – tricasse
    Dec 15, 2015 at 17:29
90

I think this is it:

sudo update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10

Using Debian alternatives.

8
  • 3
    This seems to be the better option than the accepted answer a it doesn't manually changes the /usr/bin/ folder and is using the infrastructure to alternative commands Feb 21, 2014 at 10:34
  • Haven't tried it, but I looked at the update-alternative docs. If it really works, then it's a better solution :)
    – randunel
    Mar 4, 2014 at 10:21
  • 3
    can you be more specific as to what this is doing?
    – bcorso
    Jun 9, 2014 at 23:05
  • @DominikFretz meh. The end result is exactly the same using Debian-specific command versus a POSIX compliant one. (You could have done update-alternatives --install /usr/local/bin/fribjazt node /usr/bin/nodejs 10.) To each his own, but I prefer the plain ln.
    – kojiro
    Feb 15, 2016 at 2:34
  • 2
    I had to source ~/.bashrc for this to take effect
    – iNulty
    Apr 12, 2016 at 15:31
68

Apparently the solution differs between Ubuntu versions. Following worked for me on Ubuntu 13.10:

sudo apt-get install nodejs-legacy

HTH

Edit: Rule of thumb:

If you have installed nodejs but are missing the /usr/bin/node binary, then also install nodejs-legacy. This just creates the missing softlink.

According to my tests, Ubuntu 17.10 and above already have the compatibility-softlink /usr/bin/node in place after nodejs is installed, so nodejs-legacy is missing from these releases as it is no more needed.

6
  • it seems nodejs-legacy is not maintained anymore. latest build stops at 2013-04-10
    – francoisrv
    May 26, 2014 at 20:15
  • 8
    nodejs-legacy needs not much maintainance. It just adds a softlink similar to sudo ln -s nodejs /usr/bin/node, at least on LTS 14.04
    – Tino
    Jun 10, 2014 at 15:57
  • 4
    On Ubuntu 14.04, nodejs and nodejs-legacy install the same version of Node (0.10.25). +1 to @Tino. Aug 1, 2014 at 19:19
  • Works for me in Debian Jessie as well. This should be the accepted answer as this is how things are meant to be. Only people using the amateur radio package should not do this. I'm wondering why they didn't rename the radio package like they did with chromium-bsu.
    – Jérôme
    Oct 14, 2016 at 12:25
  • This will result in 2 instances of node on your system and this is no longer maintained... Recommend you link to nodejs instead.
    – PodTech.io
    Jan 14, 2018 at 14:08
30

I have the same issue in Ubuntu 14.04.

I have installed "nodejs" and it's working, but only if I'm use command "nodejs". If I try to use "node" nothing happens.

I'm fixed this problem in next way:

  1. Install nodejs-legacy

    sudo apt-get install nodejs-legacy

After that, when I type "node" in command line I'm get an error message "/usr/sbin/node: No such file or directory"

  1. Second, what I did, it's a symbolic link on "nodejs":

    sudo ln -s /usr/bin/nodejs /usr/sbin/node
3
  • 4
    There is somethings weird on your system. node is supposed to be installed into /usr/bin/ and not /usr/sbin/. It looks for me as if you had installed the Ubuntu node package from hamradio before (see packages.ubuntu.com/trusty/all/node/filelist) and forgot to run hash -r on shell level, such that the shell still remembered the wrong path. The second ln fixed that as well, but it is no more needed after you leave that shell.
    – Tino
    Nov 27, 2014 at 1:47
  • BTW, even wrong answers are good to explain all the trouble due to three packages all of very similar names: node (/usr/sbin/node for something completely different), nodejs (/usr/bin/nodejs) and nodejs-legacy (/usr/bin/node, depends on package nodejs).
    – Tino
    Nov 27, 2014 at 1:55
  • This happened to me as well. I had installed node from source some time ago. node -v => 0.10.2 while nodejs -v => 5.5.0. Running the command which node always pointed to this local installation. In the end, I had to unset NODE_PATH, which pointed to the local installation to fix it. After this, node -v => 5.5.0 and npm install started to work for packages depending on Node => 5.0.
    – CHsurfer
    Jan 28, 2016 at 5:25
12

Node Version Manager (nvm)

If you like to install multiple nodejs versions and easily switch between them, I would suggest using Node Version Manger. It also solves the naming problem (node vs nodejs)

It's quite simple:

Install a nodejs version:

$ nvm install 4.4

Now you have nodejs 4.4 in addition to the version that was already installed and you can just use the node command to reach the newly installed version:

$ node -v    // The new version added by nvm.
v4.4.5
$ nodejs -v  // The OS version is untouched and still available.
v0.10.25

You can install more nodejs versions and easily switch between them:

$ nvm install 6.2
$ nvm use 6.2
Now using node v6.2.1 (npm v3.9.3)
$ node -v
v6.2.1
$ nvm use 4.4
Now using node v4.4.5 (npm v2.15.5)
2
11

This happened to me as well.

node -v => 0.10.2
nodejs -v => 5.5.0

The issue was that I had installed node from source some time ago. Running

which node

always pointed to this local installation. Also,

echo NODE_PATH

pointed to the local installation.

deleting the directory with the source install didn't help. It just broke the node command. In the end, unsetting the NODE_PATH environmental variable and purging then reinstalling nodejs did the trick.

unset NODE_PATH
sudo apt-get --purge remove nodejs
sudo apt-get install nodejs

After this,

node -v => 5.5.0

and npm install started to work for packages depending on Node => 5.0.

1
  • This worked for me. Too bad I messed around for an hour before finding it. Feb 9, 2016 at 20:24
10

I am new to all this, but for me a simple alias worked:

alias node='env NODE_NO_READLINE=1 rlwrap nodejs'

at least for running things directly in bash and executing .js files.

2
  • Worked without rlwrap. Thanks!
    – reconsio
    Jan 6, 2017 at 15:18
  • Thanks @Phill, you are awesome! Oct 27, 2017 at 16:48
9

How about using the official instructions from the nodejs site:

For v7:

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs

For v6:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

For v4:

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs

I've tested these from Windows bash (via subsystem for Linux - 14.04) and raspbian (ARM Debian based). Running sudo apt-get install -y nodejs without first running the setup script will result in you getting node 0.10.

If you are planning on installing native npm modules requiring build, also run:

sudo apt install -y build-essential

Note: this is the recommended path for any Debian based distro across all architectures.

7

Adding to @randunel's correct answer (can't yet comment on SO):

I also had to symlink /usr/local/bin/node to /usr/bin/nodejs as well.

sudo ln -s /usr/bin/nodejs /usr/local/bin/node

Apparently, this was overriding the /usr/bin/ node command.

No idea how that got set, but hope it helps someone else as it was a pain to figure out why the above wasn't working for me.

7

Late answer, but for up-to-date info...

If you install node.js using the recommend method from the node github installation readme, it suggests following the instructions on the nodesource blog article, rather than installing from the out of date apt-get repo, node.js should run using the node command, as well as the nodejs command, without having to make a new symlink.

This method from article is:

# Note the new setup script name for Node.js v0.12
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -

# Then install with:
sudo apt-get install -y nodejs

Note that this is for v0.12, which will get likely become outdated in the not to distant future.

Also, if you're behind a corporate proxy (like me) you'll want to add the -E option to the sudo command, to preserve the env vars required for the proxy:

curl -sL https://deb.nodesource.com/setup_0.12 | sudo -E bash -

7

This works for me:

alias node=nodejs

After following the instructions in this link.

0
4

If you are on an AWS EC2 instance running an Ubuntu instance (tested on Ubuntu 16.x), then these steps might work for you:

    sudo apt-get update
    sudo apt-get --purge remove node -y
    sudo apt-get --purge remove nodejs -y
    sudo apt-get --purge remove legacy-node -y
    sudo rm  /usr/bin/node
    curl -sL https://deb.nodesource.com/setup_6.x | sudo bash -
    sudo apt-get install nodejs -y
    node -v

If all is correct the last command shall have an output like : v6.x.x

If not then run the following:

    sudo ln -s /usr/bin/nodejs /usr/bin/node

Hopefully this will help. It helped me magically (hehe).

3

I had the same issue symbolic link helped me out: sudo ln -s /usr/bin/nodejs /usr/bin/node after that sudo npm install -g phantomjs-prebuilt

went smoothly

2

Best way to install nodejs is through NVM (Node Version Manager)

Delete previous versions :

$ sudo apt-get purge node
$ sudo apt autoremove

Also delete all node_modules by $ sudo rm -rf node_modules in the directory containing this folder.

Node & Nodejs are technically the same thing. Just the naming changed.

First Install or update nvm

to run as root

$ sudo su 

Then

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.7/install.sh | bash

OR

$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.7/install.sh | bash

Check nvm to path

$ source ~/.profile
$ nvm ls-remote

if you get error regarding the listing then install git.

$ sudo apt-get install git

Re-run :

$ nvm ls-remote
OR
$ sudo nvm ls-remote

$ nvm install version-you-require 

Checking Version

# node --version
nvm use version-you-require

INFORMATION COURTESY :

https://www.digitalocean.com/community/tutorials/how-to-install-node-js-with-nvm-node-version-manager-on-a-vps

1

I had created a symlink, but it still wasn't working.

I forgot to restart my terminal (my putty connection). After I had it worked without the symlink :)

1

Will be helpful for absolute beginners

Although, you have got the answer, just wanted to point out that the node command (without any parameters) will start node in REPL read-eval-print-loop mode to execute raw javascript code.

Another way to use node command is by providing it a js file as a parameter. This is how we mostly use it.

1

Just use NVM(Node Version Manager) - https://github.com/creationix/nvm

It has become the standard for managing Node.js.

When you need a new version:

nvm install NEW_VER
nvm use XXX

If something goes wrong you can always go back with

nvm use OLD_VER
1

You can execute this command to enable nodejs:

scl enable rh-nodejs8 bash

Note: Check your node version.

Source: https://developers.redhat.com/products/softwarecollections/hello-world/

1

https://nodejs.org/en/download/

Download .pkg file on your mac and install it. it directly works.

➜  ~ which node
/usr/local/bin/node
➜  ~ node --version
v10.11.0
➜  ~ which npm
/usr/local/bin/npm
➜  ~ npm --version
6.4.1
0

It's optional to remove the existing node and nodejs, but have to do alternatively install the latest 7.x nodejs.

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs
0

in my case, I just used this

sudo npm cache clean -f

sudo npm install -g n

sudo n stable

This one will Install a Stable Version

Then just make it symlink

sudo ln -s  /usr/local/bin/node
-1
  • First install the recommended version
  • Try in cmd node -v
  • If command work than try it in vs command
  • If it still not working "check path " in environment variable;
  • If env is set than recheck if it is working or not;
  • Then just shutdown your computer and restart it.
  • Then try it "i hope it will work "

-Restart is very important to run program properly in vs.

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