Tutorial

How To Install an Upstream Version of Node.js on Ubuntu 12.04

Published on July 17, 2012
How To Install an Upstream Version of  Node.js on Ubuntu 12.04

Status: Deprecated

This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.

About Node.js

Node.js. is a system that uses event-driven (as opposed to thread-based) programming to build scalable applications and network programs. It is especially helpful for building web servers. Written in Javascript, node.js was created in 2009 and is currently the second most popular repository on github.

Setup

Feel free to skip this section if you have a compiler and curl installed on your droplet. These steps are included since both a compiler and curl are required for the node.js installation itself. Additionally, you will need to have sudo privileges on your virtual private server for the next three commands (the actual installation does not require them).

Go ahead and run an apt-get update before starting to install any of the requirements.

sudo apt-get update

Once the update finishes, install a compiler on your VPS.

sudo apt-get install build-essential

Additionally, be sure to download curl, which we will need to perform the installation itself.

sudo apt-get install curl

Once those two components have downloaded, you are all ready to install node.js.

Install node.js and NPM (Node Package Manager)

I found the method described below to be the easiest way to install node.js. According to their site, there are eight ways to install node.js, and you can check out the other possibilities if you prefer.

This specific installation is very straightforward and installs node.js on the user's local system alone.

Start by changing the path to include commands from the ~/local/bin directory.

 echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc

Follow up by sourcing the .bashrc file:

. ~/.bashrc

Create two new directories for the installation:

mkdir ~/local
mkdir ~/node-latest-install

Switch into the latest-install folder:

cd ~/node-latest-install

Run curl to get the node.js tarball and subsequently untar it.

curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1

Once that has completed, you can go ahead and start the installation process, limiting it to the local user. This ensures that you will not need sudo later.

./configure --prefix=~/local

Run make install, but be warned: it does take a while.

make install

Finish up by downloading the the node package manager through curl:

curl -L https://npmjs.org/install.sh | sh

After you are all done, you can quickly check which version you have installed on your virtual private server.

node -v
By Etel Sverdlov

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
10 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Fixed it. The problem above usually happens when the system runs out of memory. My VPS has only 256mb RAM, and it appears gcc uses more memory to compile it in 64 bits version, so I created a swapfile following this tutorial: http://digitizor.com/2011/02/06/create-swap-file-ubuntu-linux/

Hope it helps if anyone have the same problem.

Hello, I’ve tried this install in my Vagrant machine and runs perfect, but when I shutdown the VM the installation of Node + NPM disappears, and I have got to install it all again.

Does anyone knows why?

Thanks

Works like a charm node -v 10.33 and npm -v 2.1.11

Andrew SB
DigitalOcean Employee
DigitalOcean Employee badge
May 14, 2014

@buszu64: Try: <pre> curl -L https://npmjs.org/install.sh | sh </pre>

I’ll fix that in the article.

curl https://npmjs.org/install.sh | sh

% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 193 100 193 0 0 451 0 --:–:-- --:–:-- --:–:-- 772 sh: 1: cannot open html: No such file sh: 2: Syntax error: redirection unexpected

I believe that’s not what I should see here…

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
May 13, 2014

@shrikant.khandare: What’s the output of <code>echo $PATH</code>? Try logging out and logging back in, does that fix it?

Folder structure for my ~/local/ dir is -local -bin
-include
-lib -share

I tired to set path in “bashrc” file as NODE=“/home/ubuntu/local/bin/node” NODE_PATH=“/home/ubuntu/local/lib/node_modules”

but it is not working. What should I do here.

I follow all the steps but getting following error The program ‘node’ can be found in the following packages:

  • node
  • nodejs

You’ll need curl to follow redirects when installing npm:

curl -L https://npmjs.org/install.sh | sh

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more