nodejs vs node on ubuntu 12.04
Asked Answered
L

22

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.

Loot answered 8/8, 2013 at 15:33 Comment(12)
If "you see node in /usr/bin/", then what is the output of ls -l /usr/bin/node?Wiesbaden
@Wiesbaden I got this output lrwxrwxrwx 1 root root 22 Jan 1 2013 /usr/bin/node -> /etc/alternatives/nodeLoot
Did you make any changes to shell rc?Wiesbaden
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)Wiesbaden
It printed a bunch of paths. One of them is declare -x NODE_PATH="/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript"Loot
Sorry, I'm interested in this output: declare -x PATH="....., not NODE_PATH, just PATHWiesbaden
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"Loot
Well, the path looks correct, you should see the node executable file from anywhere. When you type whereis node, what's the output?Wiesbaden
whereis node gives node: /usr/bin/node /usr/bin/X11/node /usr/share/man/man1/node.1.gz and which node gives /usr/bin/nodeLoot
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.Wiesbaden
The error says -bash: /usr/sbin/node: No such file or directory . Although usr/sbin/ is also in PATH. Thanks for your help, though!Loot
solution + explanation here: #21168641Unadvised
W
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
Wiesbaden answered 8/8, 2013 at 15:39 Comment(10)
okay! Although, if I use zsh, then the node command works.Loot
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 removedLoot
You don't need to uninstall it, after your comments, this looks like a shell problem, not a node package problem.Wiesbaden
@randunel's answer did not work for me as /usr/bin/env node would not work. @BennyMcBenBen's solution did workLegpull
I needed to make the symlink in sbin $ sudo ln -s /usr/bin/nodejs /usr/sbin/nodeAlthaalthea
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..Highkeyed
@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.Sanderling
Then as module developer i confuse which one i have to use on npm run scriptsCompo
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.Baggage
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 :)Egan
T
90

I think this is it:

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

Using Debian alternatives.

Triaxial answered 30/12, 2013 at 18:14 Comment(8)
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 commandsEquanimity
Haven't tried it, but I looked at the update-alternative docs. If it really works, then it's a better solution :)Wiesbaden
can you be more specific as to what this is doing?Faunia
@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.Culmiferous
I had to source ~/.bashrc for this to take effectSize
Worked perfectly for me with Ubuntu 16.04Muskmelon
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 @TriaxialSemang
@AnthonyKong: Accoding to man update-alternatives, the 10 is the priority of the alternative.Kinnikinnick
A
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.

Aruabea answered 5/1, 2014 at 2:23 Comment(6)
it seems nodejs-legacy is not maintained anymore. latest build stops at 2013-04-10Legpull
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.04Aruabea
On Ubuntu 14.04, nodejs and nodejs-legacy install the same version of Node (0.10.25). +1 to @Tino.Dynode
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.Kildare
This will result in 2 instances of node on your system and this is no longer maintained... Recommend you link to nodejs instead.Emblazonment
@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.Aruabea
B
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
Billups answered 10/9, 2014 at 20:54 Comment(3)
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.Aruabea
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).Aruabea
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.Phrenetic
H
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)
Hauge answered 3/6, 2016 at 10:49 Comment(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 serverSulfonation
this worked for me. Also a guide available here: digitalocean.com/community/tutorials/…Carniola
P
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.

Phrenetic answered 28/1, 2016 at 5:33 Comment(1)
This worked for me. Too bad I messed around for an hour before finding it.Mabel
C
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.

Clearway answered 11/7, 2014 at 22:15 Comment(2)
Worked without rlwrap. Thanks!Persnickety
Thanks @Phill, you are awesome!Irenics
T
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.

Tawana answered 3/10, 2016 at 17:40 Comment(0)
N
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.

Notwithstanding answered 16/7, 2014 at 20:24 Comment(0)
E
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 -

Euhemerize answered 29/5, 2015 at 13:51 Comment(0)
V
7

This works for me:

alias node=nodejs

After following the instructions in this link.

Veneering answered 5/4, 2016 at 12:41 Comment(0)
P
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).

Pumping answered 2/1, 2017 at 15:4 Comment(0)
S
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

Septenary answered 26/8, 2016 at 10:29 Comment(0)
F
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
Forjudge answered 11/9, 2016 at 17:44 Comment(0)
F
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 :)

Fretwell answered 8/2, 2015 at 16:57 Comment(0)
S
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.

Sanguine answered 6/10, 2016 at 7:41 Comment(0)
B
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
Beaune answered 6/3, 2018 at 1:6 Comment(0)
V
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/

Vittorio answered 11/6, 2018 at 14:49 Comment(0)
R
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
Readytowear answered 28/9, 2018 at 17:26 Comment(0)
F
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
Festschrift answered 23/2, 2017 at 16:28 Comment(0)
M
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
Manzanilla answered 10/7, 2022 at 13:31 Comment(0)
J
-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.

Jacobina answered 6/6, 2023 at 6:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.