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

5 Answers 5


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
ubuntu@424c7702-0947-e7c7-c532-dfec484fc109:~$ npm -v
  • @jarserver - "The following packages have unmet dependencies: nodejs : Depends: rlwrap but it is not installable E: Unable to correct problems, you have held broken packages."- Error while apt-get install. How to fix this? Sep 12, 2015 at 4:22
  • @KumarSambhav sounds like your package database is in a broken state search the site for how to fix apt broken state. Sep 14, 2015 at 3:51
  • This doesn't work for me on ubuntu 15.10 It always installs v0.10.25 (lower version than the OP, so I have no idea what's going on...) Feb 24, 2016 at 22:03
  • @HankScorpio It sounds like the apt-repo was not updated. Try following the manual installation instruction (github.com/nodesource/distributions#manual-installation) and see if that fixes it.
    – jarsever
    Feb 25, 2016 at 4:41
  • Yes, that's what the problem was. Some GPG keys (whatever they are) were missing, so apt-get update was failing every time. I used y-ppa-manager to fix the problem and now I have the latest version of NodeJS 4. Feb 25, 2016 at 18:09

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.

  • 6
    I don't think the messy permissions comment is accurate, I install node from nodesource apt repo and can run and install node modules in my local home directory (including -g global option). All it takes is updating ~/.npmrc to define your prefix directory. Sep 14, 2015 at 3:54
  • 3
    Ah, that's a very fair point. I'm still a fan of nvm for the version management aspect, but if that's not your thing, setting a prefix in ~/.npmrc definitely seems to be the right way to handle permissions for global modules. Sep 15, 2015 at 22:28
  • I believe the "outdated" note about the official repositories, in the answer is a bit ... outdated ;-) The official repositories now support any publicly released version on a supported release train - there're repos for version 6, 7 and even 8, and has been like that since at least my answer below (10/15)
    – Guss
    May 31, 2017 at 9:10

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:

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.

  • Is there any disadvantage to doing it this way? Seems like the best option...
    – Catskul
    Oct 27, 2015 at 3:36
  • 6
    It's more than one line, and allows you to learn about your system?... Some people don't like that, I think, that's the only way I can explain the curl|sh phenomenon.
    – Guss
    Oct 27, 2015 at 8:21
  • 3
    In addition to getting to learning about about your OS's package manager, it's also a security issue. curl|sh pulls a script from a server, and executes it directly in a shell. I personally trust nodesource, but it's not a great habit to get into. unix.stackexchange.com/questions/46286/… Nov 21, 2015 at 1:40
  • And there asking you to pipe it into sudo -E bash. It's running as root. I highly recommend you read, and understand the script, if you're going to pipe it from the net into a root shell. Nov 21, 2015 at 1:56
  • 1
    Generally speaking, by installing a deb package you take the same amount of risk as piping the internet into a root shell. That being said, one implies you understand your system, the other implies that you don't - and that is a huge difference.
    – Guss
    Nov 21, 2015 at 8:47

I like to use nodeenv from pypi (https://pypi.python.org/pypi/nodeenv), you install the package using pip, then setup a "node/virtualenv" and tell it to install a prebuilt version, fast and simple. Paul


This worked for me

echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install 
curl https://www.npmjs.org/install.sh | sh

Source: https://gist.github.com/isaacs/579814

  • 1
    The question is specifically about how to install NodeJS with Apt. May 31, 2017 at 9:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .