Latest node.js & npm installation on Ubuntu 12.04

Compiling is way to go for many but I am mostly in hurry so following works for me!

Adding Chris Lea’s Repo

Using Launchpad repo by Chris Lea just run following commands

apt-get install python-software-properties
apt-add-repository ppa:chris-lea/node.js
apt-get update

node.js install

apt-get install nodejs

Check node.js version

node -v

Outputs

v0.10.20

npm install

Above command should install npm.

Check npm version

npm -v

Outputs

1.4.3

If for some reason, if you see npm is not installed, you may try running:

apt-get install npm

P.S. Do not miss out on our other amazing tutorials. Stay tuned with us. Join us on twitter and facebook for more updates.

(updated on 20 Feb 2014. After this comment from dodyrw)

20 responses to “Latest node.js & npm installation on Ubuntu 12.04”

  1. Perfect, Thank you this was very helpful. I needed to install the latest node.js & npm to use the new ghost blogging platform.

  2. Followed your instructions, but I got the following error when trying to install npm:

    user@system:~$ sudo apt-get install npm
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:

    The following packages have unmet dependencies:
    npm : Depends: nodejs but it is not going to be installed
    Depends: nodejs-dev
    Depends: node-request but it is not going to be installed
    Depends: node-mkdirp but it is not going to be installed
    Depends: node-minimatch but it is not going to be installed
    Depends: node-semver but it is not going to be installed
    Depends: node-ini but it is not going to be installed
    Depends: node-graceful-fs but it is not going to be installed
    Depends: node-abbrev but it is not going to be installed
    Depends: node-nopt but it is not going to be installed
    Depends: node-fstream but it is not going to be installed
    Depends: node-rimraf but it is not going to be installed
    Depends: node-tar but it is not going to be installed
    Depends: node-which but it is not going to be installed
    E: Unable to correct problems, you have held broken packages.

    Could it be my version of nodejs?

    user@system:~$ node -v

    v0.10.25

  3. I did install Chris’s repo as instructed. When I try to install nodejs-dev, I get:

    user@system:~$ sudo apt-get install nodejs-dev
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:

    The following packages have unmet dependencies:
    nodejs-dev : Depends: nodejs (= 0.8.22-1chl1~precise1) but it is not going to be installed
    E: Unable to correct problems, you have held broken packages.

    • Now, apt-get install nodejs installs node and npm. Updated article to reflect this change.

      Just try running npm -v. You should see npm installed already.

      Please let me know if you run into any issue.

      • Yes, nodejs install node and npm, but npm installing in /usr/bin directory.
        Use ln 🙂
        root@srv1:/usr/local# ln -s /usr/bin/npm /usr/local/bin/npm
        root@srv1:/usr/local# npm -v
        1.4.3

        • Why did you need `ln` command? `/usr/bin` is also part of $PATH

  4. Like the other people here, I also get the same problem when installing npm. I have no problem with the step for nodejs.

    I don’t think we need to run: apt-get install npm
    Because when I check npm -v, it return the latest version.

    Thank you for great tutorial, it solve my problem.

    • Thanks for solution. I just tested it on new machine and it looks like npm is not installed automatically with nodejs!

      Updated article. Thanks for correction. 🙂

  5. Wayne – Massachuesetts – My name is Wayne Cataldo and I live in Somerset Massachusetts. I am 40 years old and I live with my lovely wife Jenney and my stepson Ethan and daughter Willow. All of whom are very dear to me. I’ve always been interested in how things work and was always the go to guy for car repair, computer repair or if you just needed a hand with something. I was an auto technician for over 15 years, working for a Volvo Dealership and then owning & operating my own shop for about 8 years. For the past 5 years or so I have focused on Linux, Security and WordPress and more specifically Nginx and PHP-FPM. I love opensource solutions and the communities that spring up around them. “If I have seen further, it is by standing on the shoulders of giants.”
    wayne says:

    Wheezy = https://gist.github.com/x-Code-x/2562576

    Now I just need to learn how to use it :).
    If anyone can point a total noob in the right direction for learning I would be thankful.

    Rahul I do not know how you stay on top of everything.

    Thank you camp have a good day!

  6. Carlos Alberto Umanzor Arguedas – Puntarenas, Costa Rica – I am a Web Developer since 2006, mainly focused on PHP/MySQL environments but also developing .NET projects. I also have 8 years of experience as QA Engineer and I´m pretty competent with virtual environments, aws and network devices. I received my bachelor degree in Enterprise Computer science from UCR in Puntarenas, Costa Rica around the year 2005. Currently I'm finishing my studies in UNED in order to obtain Licentiate degree in Computer Sciences with an emphasis in Web application development. My main objetive is to overcome all challenges, no matter how hard them could be, for me, the solution for a problem is not out of our reach, we just have to think and work, that's simple. Plus, accumulating knowledge and keep learning are my daily activities in order to improve myself.
    Carlos Umanzor says:

    Great tutorial. This was actually the fix for one of my projects at my office. It works on Ubuntu 13 too, but I do recommend to uninstall any “stock” version of nodejs (the one present in ubuntu’s repo), while *it does* try to uninstall sometimes it don’t, 2 of my 5 installation did keep the older npm (or nodejs) on the system but it was easy to fix.