i've been forced to install node.js into my linux box in ubuntu by my boss and i could not find a really solution on how to do it. when i googled it everyone metioned something about PPA which i have no idea what i its, so this is the best and simple way i was able to install nodejs.
$ sudo apt-get update
$ sudo apt-get upgrade
Install the latest version. for example, version 12:
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
$ sudo apt-get install nodejs
$ node -v
v8.10.0
$ sudo apt-get install npm
$ npm -v
3.5.2
$ command -v npm
/usr/bin/npm
Now that we installed npm, we can update it with this command:
$ sudo npm install -g npm
confirm the latest version has been installed
$ /usr/local/bin/npm -v
6.10.2
$ npm -v
3.5.2
* NOTE npm still shows the old version? by why? - Because its hashed! to fix it, follow these commands, you can confirm this by executing the following command
$ command -v npm
/usr/bin/npm
$ type npm
npm is hashed (/usr/bin/npm)
To fix this issue, all you have to do is send this shell command:
$ hash -d npm
NOTE: you will not get any output on this command, its normal so dont panic!
Confirm you've fixed npm with the latest version:
$ npm -v
6.10.2
$ command -v npm
/usr/local/bin/npm
You are done with npm, its time to update nodeJs. To be able to update nodejs we will use n module from npm.
$ sudo npm cache clean -f
$ sudo npm install -g n
/usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n
+ [email protected]
added 1 package from 4 contributors in 0.514s
You have two options here, you can upgrade to the stable version (LTS) or the current version
$ sudo n stable
installing : node-v10.16.0
mkdir : /usr/local/n/versions/node/10.16.0
fetch : https://nodejs.org/dist/v10.16.0/node-v10.16.0-linux-x64.tar.gz
To upgrade to latest version (and not current stable) version, you can use$ sudo n latest
installing : node-v12.7.0
mkdir : /usr/local/n/versions/node/12.7.0
installed : v12.7.0
$ /usr/local/bin/node -v
v10.6.0
$ node -v
v8.10.0
Notice the difrences here, what we want is four our node to be v10 not v8. to fix this, you need to delete the hash
$ hash -d
$ node -v
v10.6.0
Now that the hash was removed, we can clearly see v10
I know this is alot of commands. I wish there was an easy way. If I find one, I will post it here.
Hope that help.
Resources:
https://askubuntu.com/questions/1036278/npm-is-incorrect-version-on-latest-ubuntu-18-04-installation
WORKS!! HOW TO UPDATE NODEJS IN UBUNTU:
https://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version
[ERROR] ng has unexpectedly closed (exit code 127)
https://stackoverflow.com/questions/51569546/ionic-a-utility-cli-has-unexpectedly-closed