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
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 :)
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.
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)
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).
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
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.