How to install NodeJS 4 using apt?

How can I install NodeJS 4 on Ubuntu using apt-get utilities?


Solution 1:

Instructions were taken from here: https://github.com/nodesource/distributions

wget -qO- https://deb.nodesource.com/setup_4.x | sudo bash -

and then:

sudo apt-get install nodejs

Here is the system versions:

ubuntu@424c7702-0947-e7c7-c532-dfec484fc109:~$ lsb_release -r
Release:    15.04
ubuntu@424c7702-0947-e7c7-c532-dfec484fc109:~$ node -v
v4.0.0
ubuntu@424c7702-0947-e7c7-c532-dfec484fc109:~$ npm -v
2.14.2

Solution 2:

Node Version Manager always has the latest

I'm strongly of the opinion that installing Node with Node Version Manager is the best option on Ubuntu, if you're installing it on a computer where you intend to do development (instead of a production server).

When you install through the official repositories, you end up with something terribly outdated. You can always add a PPA, but you'll still end up with messy permissions where globally installing modules from npm requires admin privileges.

With NVM, everything is kept in your home folder (so no need for sudo), and you can install multiple versions of Node (including 4.0) and switch between them with ease.

Installation with NVM

Taken from the NVM installation instructions:

Grab the latest copy of NVM (you may need to sudo apt-get install curl first):

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.26.1/install.sh | bash

Tell your shell to use nvm (you may want to add this to ~/.bashrc so it happens automatically in the future):

source ~/.nvm/nvm.sh

Then install the latest node version:

nvm install 4.0

And tell nvm which version of Node you want to use:

nvm use 4.0

You may also want to add the nvm use 4.0 line to your ~/.bashrc, so that you don't have to pick a node version each time you start your terminal.

Now if you check which node it should give you a path to the node executable inside your home folder. Running node --version should tell you you're running v4.0.0.

Solution 3:

With kudus to @jarsever, I personally don't subscribe to the "curl|sh" paradigm.

If you feel the same kind of unease as I do when asked to just pipe some arbitrary text off the internet and into a root account's shell process, then you may want to try this for the same effect but with (slightly) less fear, uncertainty and doubt:

version=4
apt-key adv --keyserver keyserver.ubuntu.com --recv 68576280
apt-add-repository 'deb https://deb.nodesource.com/node_${version}.x precise main'
apt-get update
apt-get install nodejs

I believe the process should be clear, and you can also do the same through Ubuntu's Software Properties UI.