Node.js may be installed via three major methods on Ubuntu and its official derivatives.
The first method is via APT (or by the front-end, the Ubuntu Software Center) by running:
sudo apt-get install nodejs
the problem, however, is that Node.js installed this way is usually very out of date.
Via APT, cURL and nodesource
Alternately, Node.js may be installed via running:
sudo apt-get install -y curl curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash - sudo apt-get install -y nodejs
The version provided via this method is usually up to date and even when it is not it is usually only out of date by at most a few days. This installation will be automatically updated whenever one runs Software Updater.
If one requires the very latest version, or another version that is not available by either of these two methods one can install from source code. This is usually the most time-consuming of methods, potentially taking over an hour, depending on one's platform, although most of this is automated requiring very little user input. To get the source code one can go to http://nodejs.org/dist/, to find a URL for the release they want (which is
http://nodejs.org/dist/latest/node-$ver.tar.gz for the latest release, where
$ver is replaced with the latest available version with the letter
v in front of it, for example,
$ver=v0.12.7 for version 0.12.7). One can then download this release from one's web browser, via filezilla, via wget or via whatever download manager one would prefer. For simplicity's sake the next code assumes one is downloading the tarball for Node.js version 0.5.1+ via wget, in which case the code is (run from the directory to which you want the source code downloaded):
#Install the dependencies; if you are installing Node.js 0.6.x you will also #need libssl-dev sudo apt-get install build-essential python #Setting the version one is installing, remember the v! ver=v0.12.7 wget -c http://nodejs.org/dist/$ver/node-$ver.tar.gz tar -xzf node-$ver.tar.gz cd node-$ver ./configure make sudo make install
note that at the
tar line one can specify where the source code is extracted to if one wishes (via adding
-C DESTDIR where DESTDIR is the destination of the source code), but if one does one will need to adjust the next line to
cd DESTDIR. This installation may be more flexible than the previously-outlined methods but it will not automatically update itself. Instead to update a source installation one will need to re-run lines 5-10 with the updated
If one anticipates updating Node.js manually often (e.g., if one wants the latest release of Node.js as soon as it is released) it may be best to use git instead to get the source code. Although this method will take up more hard disk drive (HDD) space and is a larger download (>100 MB), hence it is only recommended for those planning to update their Node.js installation regularly.
To get the source code via git and then install it run:
sudo apt-get install git #Installing git git clone https://github.com/joyent/node.git cd node git remote add upstream https://github.com/joyent/node.git #Again, replace this with the latest available release ver=v0.12.7 git fetch upstream git checkout $ver ./configure make sudo make install
then to update this installation re-run the last 6 lines (from
ver=v0.12.7 down) of this code, with an updated