I have previously installed node.js using a third party build script but I think it’s better to do the basics piece by piece to more fully understand the whole stack.
To be honest, it’s pretty simple.
Steps to install node.js on Ubuntu 12.04 using terminal
We’ll be using the Ubuntu “Advanced Packaging Tool” (APT) to manage the installation. All code samples below should be run in a terminal window.
1: Make sure APT is up to date
In order to get the latest versions of the packages we’re going to install we need to update the APT Index:
sudo apt-get update
2: Check for dependencies
Node needs a couple of things to run properly, so let’s start off checking if they’re already installed, and installing them if necessary.
2.1: Check for a C compiler:
If you have one installed you’ll get an output something like this:
If you don’t see something similar, install one (yes, that is meant to be a ‘g’ below!):
sudo apt-get install g++
2.2: Check Python is installed:
If Python is installed this will drop you into a Python command line like this (press Ctrl+D to drop back to the terminal prompt):
If you don’t see something like that, install Python:
sudo apt-get install python-software-properties
3: Install Node.js
Now to install Node.js. Fortunately this is also available through APT making life pretty easy for us:
sudo apt-get install nodejs
No really. See, I wasn’t kidding when I said it was pretty simple!
Next up, we’ll be testing the node.js install through a few simple terminal commands, before building a quick webpage we can view in the browser.