How to build Node.JS from source on CentOS 7


Step 1: download source

[root@tutorialspots ~]# wget https://nodejs.org/dist/v10.13.0/node-v10.13.0.tar.gz
--2018-11-12 22:25:05--  https://nodejs.org/dist/v10.13.0/node-v10.13.0.tar.gz
Resolving nodejs.org (nodejs.org)... 104.20.22.46, 104.20.23.46, 2606:4700:10::6
814:172e, ...
Connecting to nodejs.org (nodejs.org)|104.20.22.46|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 36274534 (35M) [application/gzip]
Saving to: `node-v10.13.0.tar.gz'

100%[======================================>] 36,274,534  7.13MB/s   in 5.5s

2018-11-12 22:25:12 (6.24 MB/s) - `node-v10.13.0.tar.gz' saved [36274534/3627453
4]

Step 2: decompression

tar -xvf node-v10.13.0.tar.gz

Result:

...
node-v10.13.0/benchmark/buffers/buffer-tostring.js
node-v10.13.0/benchmark/buffers/buffer-write-string.js
node-v10.13.0/benchmark/buffers/buffer-write.js
node-v10.13.0/benchmark/buffers/buffer-zero.js
node-v10.13.0/benchmark/buffers/dataview-set.js
node-v10.13.0/benchmark/async_hooks/gc-tracking.js
node-v10.13.0/benchmark/assert/deepequal-buffer.js
node-v10.13.0/benchmark/assert/deepequal-map.js
node-v10.13.0/benchmark/assert/deepequal-object.js
node-v10.13.0/benchmark/assert/deepequal-prims-and-objs-big-array-set.js
node-v10.13.0/benchmark/assert/deepequal-prims-and-objs-big-loop.js
node-v10.13.0/benchmark/assert/deepequal-set.js
node-v10.13.0/benchmark/assert/deepequal-typedarrays.js
node-v10.13.0/benchmark/assert/ok.js
node-v10.13.0/benchmark/assert/throws.js

Step 3: change dir

cd node-v10.13.0

Step 4: install gcc-c++

[root@tutorialspots node-v10.13.0]# yum install gcc-c++
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.0x.sg
 * epel: d2lzkl7pfhq30w.cloudfront.net
 * extras: centos.netonboard.com
 * remi: ftp.riken.jp
 * remi-php71: ftp.riken.jp
 * remi-safe: ftp.riken.jp
 * updates: centos.netonboard.com
Resolving Dependencies
--> Running transaction check
---> Package gcc-c++.x86_64 0:4.8.5-28.el7_5.1 will be installed
--> Processing Dependency: libstdc++-devel = 4.8.5-28.el7_5.1 for package: gcc-c
++-4.8.5-28.el7_5.1.x86_64
--> Processing Dependency: gcc = 4.8.5-28.el7_5.1 for package: gcc-c++-4.8.5-28.
el7_5.1.x86_64
--> Processing Dependency: libmpfr.so.4()(64bit) for package: gcc-c++-4.8.5-28.e
l7_5.1.x86_64
--> Processing Dependency: libmpc.so.3()(64bit) for package: gcc-c++-4.8.5-28.el
7_5.1.x86_64
--> Running transaction check
---> Package gcc.x86_64 0:4.8.5-28.el7_5.1 will be installed
--> Processing Dependency: cpp = 4.8.5-28.el7_5.1 for package: gcc-4.8.5-28.el7_
5.1.x86_64
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.8.5-28.el
7_5.1.x86_64
---> Package libmpc.x86_64 0:1.0.1-3.el7 will be installed
---> Package libstdc++-devel.x86_64 0:4.8.5-28.el7_5.1 will be installed
---> Package mpfr.x86_64 0:3.1.1-4.el7 will be installed
--> Running transaction check
---> Package cpp.x86_64 0:4.8.5-28.el7_5.1 will be installed
---> Package glibc-devel.x86_64 0:2.17-222.el7 will be installed
--> Processing Dependency: glibc-headers = 2.17-222.el7 for package: glibc-devel
-2.17-222.el7.x86_64
--> Processing Dependency: glibc-headers for package: glibc-devel-2.17-222.el7.x
86_64
--> Running transaction check
---> Package glibc-headers.x86_64 0:2.17-222.el7 will be installed
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.
17-222.el7.x86_64
--> Processing Dependency: kernel-headers for package: glibc-headers-2.17-222.el
7.x86_64
--> Running transaction check
---> Package kernel-headers.x86_64 0:3.10.0-862.14.4.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package              Arch        Version                    Repository    Size
================================================================================
Installing:
 gcc-c++              x86_64      4.8.5-28.el7_5.1           updates      7.2 M
Installing for dependencies:
 cpp                  x86_64      4.8.5-28.el7_5.1           updates      5.9 M
 gcc                  x86_64      4.8.5-28.el7_5.1           updates       16 M
 glibc-devel          x86_64      2.17-222.el7               base         1.1 M
 glibc-headers        x86_64      2.17-222.el7               base         678 k
 kernel-headers       x86_64      3.10.0-862.14.4.el7        updates      7.1 M
 libmpc               x86_64      1.0.1-3.el7                base          51 k
 libstdc++-devel      x86_64      4.8.5-28.el7_5.1           updates      1.5 M
 mpfr                 x86_64      3.1.1-4.el7                base         203 k

Transaction Summary
================================================================================
Install  1 Package (+8 Dependent packages)

Total download size: 40 M
Installed size: 84 M
Is this ok [y/d/N]: y
Downloading packages:
(1/9): cpp-4.8.5-28.el7_5.1.x86_64.rpm                     | 5.9 MB   00:00
(2/9): gcc-c++-4.8.5-28.el7_5.1.x86_64.rpm                 | 7.2 MB   00:00
(3/9): glibc-devel-2.17-222.el7.x86_64.rpm                 | 1.1 MB   00:00
(4/9): glibc-headers-2.17-222.el7.x86_64.rpm               | 678 kB   00:00
(5/9): libmpc-1.0.1-3.el7.x86_64.rpm                       |  51 kB   00:00
(6/9): kernel-headers-3.10.0-862.14.4.el7.x86_64.rpm       | 7.1 MB   00:00
(7/9): libstdc++-devel-4.8.5-28.el7_5.1.x86_64.rpm         | 1.5 MB   00:00
(8/9): mpfr-3.1.1-4.el7.x86_64.rpm                         | 203 kB   00:00
(9/9): gcc-4.8.5-28.el7_5.1.x86_64.rpm                     |  16 MB   00:00
--------------------------------------------------------------------------------
Total                                               49 MB/s |  40 MB  00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mpfr-3.1.1-4.el7.x86_64                                      1/9
  Installing : libmpc-1.0.1-3.el7.x86_64                                    2/9
  Installing : cpp-4.8.5-28.el7_5.1.x86_64                                  3/9
  Installing : kernel-headers-3.10.0-862.14.4.el7.x86_64                    4/9
  Installing : glibc-headers-2.17-222.el7.x86_64                            5/9
  Installing : glibc-devel-2.17-222.el7.x86_64                              6/9
  Installing : gcc-4.8.5-28.el7_5.1.x86_64                                  7/9
  Installing : libstdc++-devel-4.8.5-28.el7_5.1.x86_64                      8/9
  Installing : gcc-c++-4.8.5-28.el7_5.1.x86_64                              9/9
  Verifying  : libstdc++-devel-4.8.5-28.el7_5.1.x86_64                      1/9
  Verifying  : gcc-4.8.5-28.el7_5.1.x86_64                                  2/9
  Verifying  : mpfr-3.1.1-4.el7.x86_64                                      3/9
  Verifying  : glibc-devel-2.17-222.el7.x86_64                              4/9
  Verifying  : cpp-4.8.5-28.el7_5.1.x86_64                                  5/9
  Verifying  : glibc-headers-2.17-222.el7.x86_64                            6/9
  Verifying  : libmpc-1.0.1-3.el7.x86_64                                    7/9
  Verifying  : kernel-headers-3.10.0-862.14.4.el7.x86_64                    8/9
  Verifying  : gcc-c++-4.8.5-28.el7_5.1.x86_64                              9/9

Installed:
  gcc-c++.x86_64 0:4.8.5-28.el7_5.1

Dependency Installed:
  cpp.x86_64 0:4.8.5-28.el7_5.1
  gcc.x86_64 0:4.8.5-28.el7_5.1
  glibc-devel.x86_64 0:2.17-222.el7
  glibc-headers.x86_64 0:2.17-222.el7
  kernel-headers.x86_64 0:3.10.0-862.14.4.el7
  libmpc.x86_64 0:1.0.1-3.el7
  libstdc++-devel.x86_64 0:4.8.5-28.el7_5.1
  mpfr.x86_64 0:3.1.1-4.el7

Complete!

Step 5:

[root@tutorialspots node-v10.13.0]# ./configure
creating icu_config.gypi
* Using ICU in deps/icu-small
creating icu_config.gypi
{ 'target_defaults': { 'cflags': [],
                       'default_configuration': 'Release',
                       'defines': [],
                       'include_dirs': [],
                       'libraries': []},
  'variables': { 'asan': 0,
                 'build_v8_with_gn': 'false',
                 'coverage': 'false',
                 'debug_nghttp2': 'false',
                 'enable_lto': 'false',
                 'enable_pgo_generate': 'false',
                 'enable_pgo_use': 'false',
                 'force_dynamic_crt': 0,
                 'gas_version': '2.27',
                 'host_arch': 'x64',
                 'icu_data_in': '../../deps/icu-small/source/data/in/icudt62l.da
t',
                 'icu_endianness': 'l',
                 'icu_gyp_path': 'tools/icu/icu-generic.gyp',
                 'icu_locales': 'en,root',
                 'icu_path': 'deps/icu-small',
                 'icu_small': 'true',
                 'icu_ver_major': '62',
                 'llvm_version': 0,
                 'node_byteorder': 'little',
                 'node_debug_lib': 'false',
                 'node_enable_d8': 'false',
                 'node_enable_v8_vtunejit': 'false',
                 'node_install_npm': 'true',
                 'node_module_version': 64,
                 'node_no_browser_globals': 'false',
                 'node_prefix': '/usr/local',
                 'node_release_urlbase': '',
                 'node_shared': 'false',
                 'node_shared_cares': 'false',
                 'node_shared_http_parser': 'false',
                 'node_shared_libuv': 'false',
                 'node_shared_nghttp2': 'false',
                 'node_shared_openssl': 'false',
                 'node_shared_zlib': 'false',
                 'node_tag': '',
                 'node_target_type': 'executable',
                 'node_use_bundled_v8': 'true',
                 'node_use_dtrace': 'false',
                 'node_use_etw': 'false',
                 'node_use_openssl': 'true',
                 'node_use_pch': 'false',
                 'node_use_perfctr': 'false',
                 'node_use_v8_platform': 'true',
                 'node_with_ltcg': 'false',
                 'node_without_node_options': 'false',
                 'openssl_fips': '',
                 'openssl_no_asm': 0,
                 'shlib_suffix': 'so.64',
                 'target_arch': 'x64',
                 'v8_enable_gdbjit': 0,
                 'v8_enable_i18n_support': 1,
                 'v8_enable_inspector': 1,
                 'v8_no_strict_aliasing': 1,
                 'v8_optimized_debug': 0,
                 'v8_promise_internal_field_count': 1,
                 'v8_random_seed': 0,
                 'v8_trace_maps': 0,
                 'v8_typed_array_max_size_in_heap': 0,
                 'v8_use_snapshot': 'true',
                 'want_separate_host_toolset': 0}}
creating config.gypi
creating config.status
creating config.mk
running:
    python tools/gyp_node.py --no-parallel -f make-linux

If you get warnings:

[root@tutorialspots node-v11.8.0]# ./configure
WARNING: C++ compiler too old, need g++ 4.9.4 or clang++ 3.4.2 (CXX=g++)
WARNING: warnings were emitted in the configure phase

You can install g++ >= 4.9.4
How to build your custom GCC on CentOS

CXX=$HOME/gcc/bin/gcc ./configure

Step 6:

make
make install

You must wait a long time, be patient!

Result:

installing /usr/local/include/node/openssl/archs/aix-gcc/asm/include/openssl/ope
nsslconf.h
installing /usr/local/include/node/openssl/archs/darwin64-x86_64-cc/no-asm/inclu
de/openssl/opensslconf.h
installing /usr/local/include/node/openssl/archs/darwin-i386-cc/asm/crypto/build
inf.h
installing /usr/local/include/node/openssl/archs/linux-ppc64/asm/include/openssl
/opensslconf.h
installing /usr/local/include/node/openssl/archs/linux-aarch64/asm/include/progs
.h
installing /usr/local/include/node/openssl/archs/darwin64-x86_64-cc/asm/crypto/i
nclude/internal/bn_conf.h
installing /usr/local/include/node/openssl/archs/darwin64-x86_64-cc/asm/crypto/i
nclude/internal/dso_conf.h
installing /usr/local/include/node/openssl/archs/BSD-x86_64/asm/include/progs.h
installing /usr/local/include/node/openssl/archs/linux-ppc64/asm/crypto/buildinf
.h
installing /usr/local/include/node/openssl/archs/VC-WIN64A/asm/crypto/include/in
ternal/bn_conf.h
installing /usr/local/include/node/openssl/archs/VC-WIN64A/asm/crypto/include/in
ternal/dso_conf.h
installing /usr/local/include/node/openssl/archs/linux64-s390x/asm/crypto/buildi
nf.h
installing /usr/local/include/node/openssl/archs/linux32-s390x/asm/crypto/buildi
nf.h
installing /usr/local/include/node/zconf.h
installing /usr/local/include/node/zlib.h

Done! check

[root@tutorialspots node-v10.13.0]# node -v
v10.13.0

Leave a Reply