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.

cchamberlain
  • 17,444
  • 7
  • 59
  • 72
Jatin
  • 14,112
  • 16
  • 49
  • 78
  • 1
    If "you see node in /usr/bin/", then what is the output of `ls -l /usr/bin/node`? – randunel Aug 08 '13 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 08 '13 at 16:00
  • Did you make any changes to shell rc? – randunel Aug 08 '13 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 08 '13 at 16:17
  • It printed a bunch of paths. One of them is `declare -x NODE_PATH="/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript"` – Jatin Aug 08 '13 at 16:24
  • Sorry, I'm interested in this output: `declare -x PATH=".....`, not `NODE_PATH`, just `PATH` – randunel Aug 08 '13 at 16:25
  • `declare -x PATH="/home/jatin/.rvm/gems/ruby-1.9.2-p320/bin:/home/jatin/.rvm/gems/ruby-1.9.2-p320@global/bin:/home/jatin/.rvm/rubies/ruby-1.9.2-p320/bin:/home/jatin/.rvm/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"` – Jatin Aug 08 '13 at 16:28
  • Well, the path looks correct, you should see the `node` executable file from anywhere. When you type `whereis node`, what's the output? – randunel Aug 08 '13 at 16:30
  • `whereis node` gives `node: /usr/bin/node /usr/bin/X11/node /usr/share/man/man1/node.1.gz` and `which node` gives `/usr/bin/node` – Jatin Aug 08 '13 at 16:46
  • I give up :D You see node and it prints `No such file or directory` when attempting to run it. You should ask about this at `http://unix.stackexchange.com/`, since it does not seem to be `nodejs` related. – randunel Aug 08 '13 at 16:48
  • The error says `-bash: /usr/sbin/node: No such file or directory` . Although `usr/sbin/` is also in PATH. Thanks for your help, though! – Jatin Aug 08 '13 at 16:49
  • 1
    solution + explanation here: https://stackoverflow.com/questions/21168141/cannot-install-packages-using-node-package-manager-in-ubuntu/21171188#21171188 – throbi Apr 15 '16 at 10:08

22 Answers22

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
Shiva
  • 11,485
  • 2
  • 67
  • 84
randunel
  • 8,917
  • 1
  • 26
  • 24
  • okay! Although, if I use `zsh`, then the `node` command works. – Jatin Aug 08 '13 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 08 '13 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 08 '13 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 '14 at 14:36
  • I needed to make the symlink in sbin $ sudo ln -s /usr/bin/nodejs /usr/sbin/node – Ouananiche Oct 09 '14 at 03:22
  • Thanks randunel, i just echoed my `$PATH `first by using `echo $PATH` And then i created a symlink for my applications executable in one of the paths like `/usr/local/bin` ..works awesome.. – Bharat Apr 06 '15 at 17:56
  • 2
    @Tino's [answer](http://stackoverflow.com/a/20929278/1424087) 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 '15 at 17:29
  • Then as module developer i confuse which one i have to use on npm run scripts – Adi Prasetyo Mar 26 '16 at 06:43
  • The irony is that the Amateur Packet Radio Node program changed their products names. Changing node to nodejs should be in the book of top 10 software blunders of the century. Such a mess. Despite Windows dominating the desktop market, this name change breaks so many things on Windows as it expects the shebang to be node not nodejs.. They need to eat crow and put the name back. – Andrew T Finnell Sep 10 '16 at 19:17
  • On Ubuntu server, just installed nodejs and then used `sudo ln -s \`which nodejs\` /usr/sbin/node`. `/usr/sbin` being the difference for a server of this kind. Might be helpful to some hopefully :) – Joshua Michael Calafell Oct 15 '16 at 17:07
90

I think this is it:

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

Using Debian alternatives.

user229115
  • 1,071
  • 7
  • 9
  • 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 – Dominik Fretz Feb 21 '14 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 04 '14 at 10:21
  • 3
    can you be more specific as to what this is doing? – bcorso Jun 09 '14 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 '16 at 02:34
  • 2
    I had to `source ~/.bashrc` for this to take effect – iNulty Apr 12 '16 at 15:31
  • Worked perfectly for me with Ubuntu 16.04 – PJP Nov 04 '16 at 09:36
  • This is a much cleaner and self-explanatory approach. Still works in 2016 on Ubuntu 16.04, node v7.3.0 and npm v4.6.1. Never install nodejs from Ubuntu's default repos! Thanks for awesome answer @user229115 – InamTaj May 23 '17 at 15:03
  • @AnthonyKong: Accoding to `man update-alternatives`, the `10` is the priority of the alternative. – Florian Brucker Jun 20 '19 at 21:06
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.

Tino
  • 9,583
  • 5
  • 55
  • 60
  • it seems nodejs-legacy is not maintained anymore. latest build stops at 2013-04-10 – francoisrv May 26 '14 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 '14 at 15:57
  • 4
    On Ubuntu 14.04, nodejs and nodejs-legacy install the same version of Node (0.10.25). +1 to @Tino. – Mark E. Haase Aug 01 '14 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 '16 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 '18 at 14:08
  • @Hariboo (Rule of thumb added to my answer.) I tried with Ubuntu 13.10, 14.04 and 16.04. `nodejs-legacy` does not install a second package, it just creates a softlink of `/usr/bin/node` which points to `/usr/bin/nodejs`. There is no much need to "maintain" a softlink, hence it can be "unmaintained". `nodejs-legacy` is missing in Ubuntu 17.10 as well as in (upcoming) Ubuntu 18.04, because `nodejs` now includes the softlink, which previously was in `nodejs-legacy`, so there is no more need for `nodejs-legacy`. – Tino Jan 24 '18 at 15:58
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
Dmytro Medvid
  • 4,988
  • 3
  • 25
  • 29
  • 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 http://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 '14 at 01: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 '14 at 01: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 '16 at 05: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)
Rotareti
  • 49,483
  • 23
  • 112
  • 108
  • 2
    That's resolved my issue, thanks a lot, I found some useful command for `nvm` on [How To Install Node.js on an Ubuntu 14.04 server](https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-an-ubuntu-14-04-server) – Huy Nguyen Aug 16 '16 at 15:29
  • 1
    this worked for me. Also a guide available here: https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-an-ubuntu-14-04-server#how-to-install-using-nvm – Koen Cornelis Sep 07 '17 at 08:25
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.

CHsurfer
  • 1,304
  • 1
  • 15
  • 34
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.

Phill
  • 525
  • 6
  • 15
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.

cchamberlain
  • 17,444
  • 7
  • 59
  • 72
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.

kfblake
  • 129
  • 1
  • 9
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 -

solsTiCe
  • 379
  • 5
  • 15
Erresen
  • 1,923
  • 1
  • 22
  • 41
7

This works for me:

alias node=nodejs

After following the instructions in this link.

Burak Tutanlar
  • 140
  • 2
  • 11
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).

Vivek
  • 492
  • 6
  • 15
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

arr
  • 31
  • 1
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
Sumit Lahiri
  • 505
  • 6
  • 13
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 :)

Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291
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.

Zameer Ansari
  • 28,977
  • 24
  • 140
  • 219
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/

tk3
  • 990
  • 1
  • 13
  • 18
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
Ashok R
  • 19,892
  • 8
  • 68
  • 68
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
Daniel
  • 3,541
  • 3
  • 33
  • 46
gino
  • 179
  • 1
  • 3
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
Sajibe Kanti
  • 181
  • 1
  • 9
-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.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31