How to Install Nodejs on Ubuntu

How to Install Nodejs on Ubuntu

Today I am going to show How to install nodejs on your ubuntu machine of any version, you can install multiple versions of nodejs at same time using nvm.

NVM – Node Version Manager

nvm is to node what rbenv is to ruby, nvm helps us to use multiple versions of node on project level and over all system wide level, We will be using nvm to install because ubuntu does not have latest version of node. This is the easiest method of all and to stay updated on latest release of node, lets install nvm

git clone .nvm

Now we need to source the nvm directory and to the shell, Add below lines to your ~/.bashrc, ~/.profile, or ~/.zshrc based on the shell you use, so that the command will be available on you login

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/" ] && . "$NVM_DIR/"

Now get the list of available versions of nodejs

nvm ls-remote

Based on your requirement, install the node version i will go for LTS version

nvm install v6.10.0

Set this version as default

nvm alias default v6.10.0

Now Nodejs is installed

node --version

You also have access to npm (Node Package Manager) you can get many node packages with single command lets check its version

npm --version

Now suppose any of your project depends on older version of node then run this in specific project directory

echo "4.8.0" > .nvmrc
nvm use