Wednesday, October 5, 2016

Installing Specific version of NodeJs in Ubuntu using NVM


Steps For installing Specific Version of Ubuntu using NVM

In Order to install specific version of node in ubuntu we will be using a tool called NVM which stands for node version manager.

NVM helps us to install and manage multiple versions of node in a single machine.It helps to switch between different versions 

To install NVM , Run below commands in a terminal


  • sudo apt-get update
  • sudo apt-get install build-essential libssl-dev
  • curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | sh

To gain access to the nvm functionality, you'll need to log out and log back in again, or you can source the~/.profile file so that your current session knows about the changes:

source ~/.profile
Now that you have nvm installed, you can install isolated Node.js versions.
To find out the versions of Node.js that are available for installation, you can type:
nvm ls-remote
nvm install 6.0.0

You can change to what ever version you like.

Usually, nvm will switch to use the most recently installed version. You can explicitly tell nvm to use the version we just downloaded by typing:
nvm use 6.0.0

When you install Node.js using nvm, the executable is called node. You can see the version currently being used by the shell by typing:
node -v

If you have multiple Node.js versions, you can see what is installed by typing:
nvm ls

If you wish to default one of the versions, you can type:
nvm alias default 6.0.0

To remove / uninstall a version
nvm uninstall 6.0.0

To Exeute node REPL/command line with specific version
nvm run 6.0.0

In NVM, you can also use alias for setting the default version of node
nvm alias default 6.0.0.

Each version of Node.js will keep track of its own packages and has npm available to manage these.

You can learn more about the options available to you with nvm by typing:
nvm help

NodeJS installation in Ubuntu

Step-wise installation of NodeJs in Ubuntu

Note:  Tested on Ubuntu 14.10

Open Terminal in ubuntu using Ctrl+Alt+T.
Run the below commands :

sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm

This should install your NodeJS in Ubuntu.The version installed will be v0.10.* which is old but stable version.
Use below command to verify the installation 
nodejs -v 

If the above installation does not work (as in EC2 & other cloud instances) or For newer LTS versions, try installing NodeJs using PPA.

Run below commands in the terminal.

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs

The above commands will install Nodejs with 4 and above version.
In order for some npm packages to work (such as those that require building from source), you will need to install the build-essentials package too.

sudo apt-get install -y build-essential





NodeJS installation in Windows



Step-wise installation of NodeJS in windows Machines:


Download 32/64 bit latest/stable NodeJs installer according to your system compatibility. 

Note: For beginners , Download windows  64 bit  (.msi) Installer [Long Term Support]  

The above url will download node version 4.6.0 which also includes npm 2.15.9.The npm is a tool that manages all the modules which are needed by node like installation , up-gradation & removal of node modules .
Double click the installer and install with default options.
After the installation is finished, Open the command prompt and type below commands to verify the installation.

> node -v 
> npm -v

The output must give both node & npm versions like below image.



If the output are the versions , NodeJs is ready to go.

If the versions are not displayed ,check whether the node is present in environment path.If not, Add node installation directory in environment path. Default is "C:\Program Files\nodejs".

Check the above commands again .If the versions are still not displayed follow the following steps 

  1. Clear the installation 
  2. Delete installation directory - Default is  C:\Program Files\nodejs 
  3. Remove nodejs from environment path.
  4. Restart the system
  5. Install again.