Introduction

Node.js is a popular platform that is used to build quick and upgradable network applications efficiently. It achieves maximum productivity with the minimum effort needed, often used in applications used throughout many devices.

Install Nodejs

There are several ways that we can install node.js in Ubuntu 14.04. We will go over the basic install, the PPM install, and the NVM install.

The Basic install (Distro-Stable Version)

To update the current packages, the command is:

sudo apt-get update

Install the node.js package, the command is:

sudo apt-get install nodejs

Install npm(Node Package Manager)as well for package management; the command is:

sudo apt-get install npm

Verify the current version of Node.js installed, the command is:

node -v

Congratulations! You have installed Node.js using The Basic(Distro-Stable Version) install.

The PPA install (Personal Package Archive)

Install the PPA to get access to its contents; the command is:

curl -sL https://deb.nodesource.com/setup | sudo bash -

If you get the following error message “-bash: curl: command not found,” run the following command to update the apt-get file:

sudo apt-get install apt-file && apt-file update

Update your local packages; the command is:

sudo apt-get update

Install the node.js, the command is:

sudo apt-get install nodejs

Install npm(Node Package Manager)to manage your package.

sudo apt-get install npm

Verify your version of Node.js is installed; the command is:

node -v

Congratulations! You have installed Node.js using The PPA(Personal Package Archive) install.

The NVM install (Nodejs Version Manager)

The NVM install is another way of installing Node.js

using apt.

Installed through a tool called,

nvm

(Node.js version manager).

Using NVM will give you a selection of different versions of Node.js, from the latest to several previous ones.

Update the system to build the source packages; the command is:

sudo apt-get update

Install the following to make your components with the nvm script that we’ll go over next:

sudo apt-get install build-essential libssl-dev

Download then install the nvm script with the following command or get them from https://github.com/creationix/nvm

curl https://raw.githubusercontent.com/creationix/nvm/v0.7.0/install.sh | sh

The software will install in a subdirectory of your home directory

~/.nvm

and will add the necessary lines to your

~/.profile

file to use the file.

With the following command, source the

~/.profile

for your session to know about these changes, and you can access the nvm functionality.

source ~/.profile

Nvm has been installed. Now you can install whatever version of Node.js is available.

To view the versions that are currently available, the command is:

nvm ls-remote
Sample nvm output

Sample nvm output

You should see something like the following;

Install the version you want with the command:

nvm install [your version]

Example:

nvm install 0.11.16

Configure nvm to use the version of Node.js that you just downloaded; the command is:

nvm use [your version]

Example:

nvm use 0.11.16

To verify the current version of Node.js installed, the command is:

node -v

If you have a lot of Node.js versions, see what’s installed, the command is:

nvm ls
Sample nvm ls

Sample nvm ls

To default one of the versions that are installed, the command is:

nvm alias default [your version]

Example:

nvm alias default 0.11.16

You can also reference it by the following alias:

nvm use default

You can have

npm

install packages to the Node.js project’s

./node_modules

directory by using the standard format:

npm install express
Install npm

Install npm

If you’d like to install it globally (available to the other projects using the same Node.js version), you can add the

-g

flag:

npm install -g express
Install npm

Install npm

This will install the package in:

~/.nvm/node_version/lib/node_modules/package_name

Installing globally will let you run the commands from the command line, but you’ll have to use link the package into your locally to require it from within a program:

npm link express
npm Link Express

npm Link Express

Other options are available with the following command:

nvm help
Sample nvm help page

NVM Help

Congratulations! You have installed Node.js using The PPA(Personal Package Archive) install.

Learn more about our VPS hosting services and VPS hosting price.