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.
Install the required packages:
sudo apt-get install build-essential libssl-dev curl
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 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
Small inconvenience to get the latest and greatest.
How-to Install & Getting-Started with Node.js on Ubuntu 13.10 Saucy Easy Guide