How To Compile Node.js With NPM From Source On CentOS 6

Published on August 21, 2013

Brian Rogers

How To Compile Node.js With NPM From Source On CentOS 6

Status: Deprecated

This article covers a version of CentOS that is no longer supported. If you are currently operating a server running CentOS 6, we highly recommend upgrading or migrating to a supported version of CentOS.

Reason: CentOS 6 reached end of life (EOL) on November 30th, 2020 and no longer receives security patches or updates. For this reason, this guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other CentOS releases. If available, we strongly recommend using a guide written for the version of CentOS you are using.


(At the time of this writing, the current stable release is v0.10.15 for Node.js and 1.3.5 for NPM)

Now compiling Node.js from source can seem a little daunting. It may even stir up feelings of fear, after all, it's just not as normal as it used to be. But fear not, it's much easier than you think and it will take about 15 minutes from start to finish.

One good reason to compile it yourself is that you can get the most up-to-date or even a beta release version. CentOS is not known for having the latest release versions of packages, so this may have to be something you know how to do. However, there is a big pitfall to this approach; there isn't a package manager to alert you when there is an update. A second, but minor, pitfall is that when there is an update you have uninstall the old version then compile the new source the same way you would in this tutorial. Keep that in mind, and it may be prudent to sign up for their email newsletter to get alerts of when a new version is released.

This is a beginner level tutorial, it assumes the following:

  • You have a fresh CentOS 6 (x64) VPS (from DigitalOcean)
  • You have root level privileges

If you use 'sudo', you should know to prepend it to any commands specified.


We need a few things installed that don't come with the barebones install DigitalOcean provides. So let's install them to make sure we can compile source code. It will also list about two dozen dependency packages, just accept them and let the system install them all.

yum install gcc gcc-c++ automake autoconf libtoolize make

Get the Source Code

We need to download the source code from Node's website, and they make it super simple. There's a big green button on the home page that will force a download. Now, we don't need to download it to our local computer, we need it on the VPS. On your VPS, change to the directory "opt". Why change to that particular directory? Well, in the old days, "/opt" was used by UNIX vendors like AT&T, Sun, DEC and 3rd-party vendors to hold "Option" packages; i.e. packages that you might have paid extra money for. I found that answer eloquently explained here.

cd /opt

This directory is empty, so it's a good place to keep your source code that you want to compile. But now we need to get the package on the VPS. We use the tool 'wget' to download it:

wget http://nodejs.org/dist/v0.10.15/node-v0.10.15.tar.gz

Now that the package is on your VPS, extract it from the tar file.

tar zxvf node-v0.10.15.tar.gz

The option used are as follows: 'z' is to specify that the tar has been gzipped, 'x' for extraction, 'v' is for versbose, 'f' is to specify an archive file. These options combined will let tar know that the tarball file is gzipped and needs to be extracted.

Since we now have the unzipped source code, we need to get in to the directory and get things installed. So move into that directory:

cd node-v0.10.15

This folder contains raw files that need to be compiled specifically for your particular architecture and kernel. We have to create some files to give instructions during the compile. Don't worry, this is done very easily. Most source code packages like this come with a bash script called "configure" that will create all these files and set the options for you. So run the configure script:


It should only take a few seconds to complete, and it will output a lot of stuff. Unless you see anything that says "failed" or "exit code" followed by a bunch of errors, then it complete successfully. I'll assume it was successful, so we'll move on to the next step.

We need to have all the code compiled from their raw format, it's a really simple command to run.


Now go grab a drink, make a sandwhich, or possibly take a short nap. This can take roughly five minutes. Think about that, you could spin up a few VPS in the time it takes to have this compilied. It goes through all the dependecy files and compile them, link them together, and set it up to be used by the system. It will flash a bunch of long commands on your screen. You don't have to do anything, it runs all by itself. You can sit and watch it, but I personally recommend getting up and leaving the computer for a few minutes while it runs, your time will be better spent.

Once it is complete, there is only one more step. You're almost there so don't give up now. The final step is to actually install it on your system by having all the compiled files moved into various other folders on your VPS so the system can use them. This is a quick process, and once again the process is taken care of by a single command.

make install

That should only take a few moments to be done, and once it's done you can verify it has installed both Node.js and NPM:

node --version

npm --version

If you see the versions as specified above, then that's it. You're all done and have successfully compiled Node.js from scratch! You can start installing node modules through NPM or if you already have an app on your VPS you can start node to serve it up.

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
Default avatar
Brian Rogers


Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?

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!

I followed these instructions on CentOS 7 and after make install completed, I ran the following two commands:

node --version which returned v0.10.46

I then ran the following command:

npm --version which returned bash: /usr/bin/npm: No such file or directory

Any ideas about what I did wrong? Thanks. (make did not have any errors when I ran and seemed to complete successfully)

I’d probably follow this with:

$ sudo npm install n $ sudo n stable

To have the ‘n’ npm package update node for you.

You can download the latest stable version: $ wget http://nodejs.org/dist/node-latest.tar.gz $ tar xzvf node-latest.tar.gz $ cd node-v*

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
DigitalOcean Cloud Control Panel