Install Node / NPM On Ubuntu 14.04

Overview

Node is fairly new and is constantly improving. With Ubuntu LTS, the repository versions tend to stay the same version and only changing for patches. This doesn’t help with fast changing software like node.js so a manual install gets around this.

Pre Requisite

Install the required packages:
sudo apt-get install build-essential libssl-dev curl

Install

Go to http://nodejs.org and download the Linux binaries for either 32 or 64 bit. At the time I got node-v0.10.28-linux-x64.tar.gz so this will be used as the example from here on.

This guide will go through installing using root but it can also be installed without by using a different path to /usr/local e.g ~/local/

Extract the downloaded file to the directory created above:
sudo tar -xzf ~/Downloads/node-v0.10.28-linux-x64.tar.gz -C /usr/local

Rename the directory so that it is not version specific:
sudo mv /usr/local/node-v0.10.28-linux-x64 /usr/local/node

Add the binary executable directory to the shell path to save typing /usr/local/node/bin/[something]. Edit /etc/environment and append :/usr/local/node/bin onto the end of the PATH= inside the quotes. For example from:

PATH=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games”

to

PATH=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/node/bin”

For non root, edit ~/.bashrc file and append this to the file:
export PATH=$PATH:/usr/local/node/bin

Reload bash shell to pick up the changes. Root install:
source /etc/environment

Non root:
source ~/.bashrc

To check the install worked, type the following and the prompt should change:
node

To allow sudo users to run node and more importantly npm command (which allows packages to be updated) edit /etc/sudoers and append :/usr/local/node/bin to the line starting with Defaults secure_path=

NPM

NPM is installed as part of node.js but it doesn’t have execute permissions. To enable this:
sudo chmod +x /usr/local/node/lib/node_modules/npm/bin/npm.cmd

To test it works type:
npm

Summary

Small inconvenience to get the latest and greatest.

How-to Install & Getting-Started with Node.js on Ubuntu 13.10 Saucy Easy Guide

About Danny

I.T software professional always studying and applying the knowledge gained and one way of doing this is to blog. Danny also has participates in a part time project called Energy@Home [http://code.google.com/p/energyathome/] for monitoring energy usage on a premise. Dedicated to I.T since studying pure Information Technology since the age of 16, Danny Tsang working in the field that he has aimed for since leaving school. View all posts by Danny → This entry was posted in Linux and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *.

All comments must go through an approval and anti-spam process before appearing on the website. Please be patience and do not re-submit your comment if it does not appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.