Compile Node.js with NPM from source - Ubuntu or Debian
While it is generally recommended that you use the more traditional Node.js install methods, you may want to instead compile Node.js from source if you need more direct control over your Node.js environment or you want to use a custom-compiled version.
- A Ubuntu or Debian Server
- Root or sudo permissions
- Update your apt repository:
sudo apt-get update
- Install build essentials:
sudo apt-get install build-essential openssl libssl-dev pkg-config
- Change to the src directory:
- Make a node directory in your src folder:
sudo mkdir node
- Enter the node directory:
- Copy the Linux Binary from the Node.js download page and use wget to download the package. Make sure to replace the highlighted portion with node's current version:
sudo wget https://nodejs.org/dist/v6.9.2/node-v6.9.2.tar.gz
- Extract the tar file:
sudo tar zxvf node-v6.9.2.tar.gz
- Now that our source code has been extracted, move to the node directory where the highlighted portion is the current version you downloaded:
- Run the configure script:
- Compile the code:
make will begin compiling the code. This will take 5-10 minutes or even longer depending on your server resources.
- Now that make is compiled, install it:
sudo make install
- Check the Node.js version:
- Check the npm version:
This folder contains raw files that need to be compiled specifically for your particular architecture and kernel. 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.
If you don't receive any errors or warnings, the the configure script ran successfully.
If you see the versions displayed for node and npm, you have successfully compiled Node.js with npm from source. You can now begin installing node modules through npm.