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.
22 Answers 22
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
-
okay! Although, if I use
zsh
, then thenode
command works.Jatin– Jatin08/08/2013 16:04:24Commented Aug 8, 2013 at 16:04 -
2Also, how do I uninstall the Amateur Packet Radio Node program? I tried
sudo apt-get remove node
but it saysPackage node is not installed, so not removed
Jatin– Jatin08/08/2013 16:06:54Commented 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– randunel08/08/2013 16:14:10Commented 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 workfrancoisrv– francoisrv05/27/2014 14:36:00Commented May 27, 2014 at 14:36 -
2
I think this is it:
sudo update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10
Using Debian alternatives.
-
3This 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 commandsDominik Fretz– Dominik Fretz02/21/2014 10:34:09Commented 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– randunel03/04/2014 10:21:57Commented Mar 4, 2014 at 10:21 -
3can you be more specific as to what this is doing?bcorso– bcorso06/09/2014 23:05:36Commented 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 plainln
.kojiro– kojiro02/15/2016 02:34:32Commented Feb 15, 2016 at 2:34 -
2I had to
source ~/.bashrc
for this to take effectiNulty– iNulty04/12/2016 15:31:05Commented Apr 12, 2016 at 15:31
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.
-
it seems nodejs-legacy is not maintained anymore. latest build stops at 2013年04月10日francoisrv– francoisrv05/26/2014 20:15:52Commented May 26, 2014 at 20:15
-
8
nodejs-legacy
needs not much maintainance. It just adds a softlink similar tosudo ln -s nodejs /usr/bin/node
, at least on LTS 14.04Tino– Tino06/10/2014 15:57:58Commented Jun 10, 2014 at 15:57 -
4On Ubuntu 14.04, nodejs and nodejs-legacy install the same version of Node (0.10.25). +1 to @Tino.Mark E. Haase– Mark E. Haase08/01/2014 19:19:49Commented 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– Jérôme10/14/2016 12:25:41Commented 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– PodTech.io01/14/2018 14:08:03Commented Jan 14, 2018 at 14:08
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:
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"
Second, what I did, it's a symbolic link on "nodejs":
sudo ln -s /usr/bin/nodejs /usr/sbin/node
-
4There 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 Ubuntunode
package from hamradio before (see packages.ubuntu.com/trusty/all/node/filelist) and forgot to runhash -r
on shell level, such that the shell still remembered the wrong path. The secondln
fixed that as well, but it is no more needed after you leave that shell.Tino– Tino11/27/2014 01:47:13Commented 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
) andnodejs-legacy
(/usr/bin/node
, depends on packagenodejs
).Tino– Tino11/27/2014 01:55:31Commented 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
whilenodejs -v => 5.5.0
. Running the commandwhich node
always pointed to this local installation. In the end, I had tounset NODE_PATH
, which pointed to the local installation to fix it. After this,node -v => 5.5.0
andnpm install
started to work for packages depending on Node => 5.0.CHsurfer– CHsurfer01/28/2016 05:25:28Commented Jan 28, 2016 at 5:25
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)
-
2That'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 serverHuy Nguyen– Huy Nguyen08/16/2016 15:29:48Commented Aug 16, 2016 at 15:29 -
1this worked for me. Also a guide available here: digitalocean.com/community/tutorials/…Koen Cornelis– Koen Cornelis09/07/2017 08:25:19Commented Sep 7, 2017 at 8:25
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.
-
This worked for me. Too bad I messed around for an hour before finding it.Dustin Fraker– Dustin Fraker02/09/2016 20:24:43Commented Feb 9, 2016 at 20:24
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.
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.
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.
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 -
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).
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
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-remoteOR
$ 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
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 :)
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.
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
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/
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
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
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
- 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.
Explore related questions
See similar questions with these tags.
ls -l /usr/bin/node
?lrwxrwxrwx 1 root root 22 Jan 1 2013 /usr/bin/node -> /etc/alternatives/node
export | grep PATH
output when not usingzsh
? (it should print/usr/bin
among other things)