
Node JS
We can install Node JS or upgrade currently installed version to latest version via two methods
- Installing latest .tar file and
- Node Version Manager (NVM)
Installing Node JS via .tar file
Download the latest version from https://nodejs.org/en/
At the time of writing this tutorial current version of node js is 8.11.3 LTS.
1 2 3 4 5 |
VERSION=v8.11.3 DISTRO=linux-x64 sudo mkdir /usr/local/lib/nodejs sudo tar -xJvf node-$VERSION-$DISTRO.tar.xz -C /usr/local/lib/nodejs sudo mv /usr/local/lib/nodejs/node-$VERSION-$DISTRO /usr/local/lib/nodejs/node-$VERSION |
Now add it to environment variable bu running below command
1 2 |
export NODEJS_HOME=/usr/local/lib/nodejs/node-$VERSION/bin export PATH=$NODEJS_HOME:$PATH |
Check the version of node js
1 |
node -v |
Installing / upgrading Node Js via NVM
Other way to install / upgrade Node Js is via NVM (Node Version Manager)
If it is not already installed on your machine, then follow below steps to install it, skip it already installed. You can also check these steps in the official documentation of NVM here
1 2 3 |
sudo apt-get update sudo apt-get install build-essential libssl-dev curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh -o install_nvm.sh |
Run the script
1 |
bash install_nvm.sh |
Now source the profile to get the access in the current session which doesn’t require you logout and login back.
To see the list of versions available for installation run below command
1 |
nvm ls-remote |
To install a version that you need
1 |
nvm install 8.11.3 |
Tell nvm to use currently installed version
1 |
nvm use 8.11.3 |
Confirm the currently installed version by
1 |
node -v |