Social Icons

Pages

Wednesday, June 8, 2016

How to install NodeJS on Ubuntu Linux

You can install Node.js on Ubuntu by using the apt package manager by merely running the command


sudo apt-get update
sudo apt-get install nodejs

Issue with this installation is that usually ubuntu repositories have bit older version of Node.js than current stable release.

If you need the latest versions of Node.js you can install it via a tool called nvm (Node.js version manager). To install nvm, C++ compiler needs to be installed. On Ubuntu build-essential and libssl-dev packages will do the work.



sudo apt-get update
sudo apt-get install build-essential libssl-dev
After installing C++ compiler you can proceed to install (or update) nvm by using cURL command or Wget command.


curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash

Install script will be downloaded and installed to ~/.nvm folder. If you like to install the nvm into a custom folder, say to /opt/nvm. Then modify the above command as to
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | NVM_DIR="/opt/nvm" bash
But if you use any custom directory for NVM_DIR property, please make sure you have the right privileges to access it. Otherwise it will give you a hard time. Personally I advice you to download it to the default location.

To use nvm functions you have to log out and log in. Or else you can sourceyour current session in order to let it know about the changes.
source ~/.profile

Availability of nvm can be checked by using the version command.
nvm --version

How to use NVM

You can check what are the available versions of NodeJS to download.
nvm ls-remote


At this moment latest version available is v6.0.0. To install any version
nvm install version_number

If you need to install multiple versions of node you can view all your versions using
nvm ls
In order set a default version
nvm alias default version_number
nvm use default
 
Blogger Templates