How I build Node from sources on Ubuntu 16.04 (August 2018)

This is a writeup of how I built the latest stable version of node (v8.11.4 at the time of this writing) from sources and how I setup node and npm to be used from the custom build location (and not be installed system-wide, e.g. as in /usr/bin).

See in this note on how to get node with pre-built binaries.


sudo apt-get install make g++ libssl-dev git

actual build

Fetch and explode the sources:

tar xv node-v8.11.4.tar.gz
cd node-v8.11.4

I then cd into node-v8.11.4/ and created an HTML out of (using pandoc -s --toc -o /tmp/building.html)

On the supported platforms section I saw that for GNU/Linux x64, (Tier 1 support) the requirements are: kernel >= 2.6.32, glibc >= 2.12. Using uname -r and /lib/i386-linux-gnu/ I saw that I had (on my Ubuntu 16.04 machine) the 4.6.0 Linux kernel and the 2.23 glibc (GNU C Library) so everything was clear to proceed.

Following the above, the following (I used -j4 as I have 4 processors on my machine):

make -j4
… worked like a charm (both configure and make -j4 exited with 0)

The produced binary is available at out/Release/node

$ ./out/Release/node --version

running tests

The instructions on mention a way of running tests:

make test-only
… this was also executed successfully.

setting up the environment (the wrong way)

Following the above I placed the out/Release directory ahead of my PATH in my .bashrc file and sure enough:

$ node --version

using npm from sources

Given that the node-v8.11.4/out/Release directory is now in the $PATH I simply created a symlink from that directory to the file npm-cli.js:

ln -s ../../deps/npm/bin/npm-cli.js npm
See also my question in the nodejs github issue tracker.

setting up the environment (the right way)

Some time after the above I received a reply in the github issue tracker to the effect that I simply have to to run the makefile's install target specifying PREFIX. This automatically takes care of creating the expected npm symlinks (alongside the node executable).

Given this information, I executed the following:

make install PREFIX=/home/mperdikeas/node/8.11.4/
… which worked like a charm and then I updated the PATH in my .bashrc accordingly.