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.
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
vsnodejs
)It's quite simple:
Install a nodejs version:
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:You can install more nodejs versions and easily switch between them:
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 ajs
file as a parameter. This is how we mostly use it.You can execute this command to enable nodejs:
Note: Check your node version.
Source: https://developers.redhat.com/products/softwarecollections/hello-world/
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:
If something goes wrong you can always go back with
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.
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.
Best way to install nodejs is through NVM (Node Version Manager)
Delete previous versions :
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
Then
OR
Check nvm to path
if you get error regarding the listing then install git.
Re-run :
ORChecking Version
INFORMATION COURTESY :