Table of Contents
In this article, we will see how to install the latest version of Node.js on Ubuntu/Debian based systems. Many times you might have observed that when you try to install a package through NPM, the installation fails with the message that you need to install the latest version of node in your System. This problem usually occurs when you installed Node.js from some repository or from node version manager which might not contain the latest version of Node.
So to solve this problem you need to download and install Node.js from official website which always contains the latest version. I would mostly prefer to use the source code for installation. Hence here we will see the steps to install Node.js through source code on Ubuntu/Debian based systems.
How to Install the latest version of Node.js on Ubuntu/Debian
Also Read: How to Install Jshon on Ubuntu 20.04 LTS (Focal Fossa)
Step 1: Prerequisites
a) You should have a running Ubuntu/Debian
System.
b) You should have sudo
or root
access to run privileged commands.
c) You should have latest version of Python 3
installed in your System.
Step 2: Update Your Server
In the first step, you need to install all the latest available updates using sudo apt update
command and then upgrade all the packages to the latest version by using sudo apt upgrade
command as shown below.
cyberithub@ubuntu:~$ sudo apt update && sudo apt upgrade
Hit:1 http://in.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://ppa.launchpad.net/flatpak/stable/ubuntu focal InRelease
Get:3 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Hit:4 https://dl.winehq.org/wine-builds/ubuntu focal InRelease
Get:5 https://dl.google.com/linux/chrome/deb stable InRelease [1,811 B]
Get:6 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Hit:7 https://download.sublimetext.com apt/stable/ InRelease
Get:8 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:9 https://dl.google.com/linux/chrome/deb stable/main amd64 Packages [1,063 B]
Get:10 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [2,083 kB]
Get:11 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [2,465 kB]
Get:12 http://security.ubuntu.com/ubuntu focal-security/main i386 Packages [574 kB]
Get:13 http://in.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [805 kB]
Get:14 http://security.ubuntu.com/ubuntu focal-security/main Translation-en [338 kB]
Get:15 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [59.8 kB]
Get:16 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [820 kB]
Get:17 http://in.archive.ubuntu.com/ubuntu focal-updates/main Translation-en [420 kB]
.....................................................................
Step 3: Download Node.js
In the next step, you need to visit the official website and download the latest node.js
package by using wget
or curl
utility as shown below. This will download the compressed package in your local system directory.
cyberithub@ubuntu:~$ wget https://nodejs.org/dist/v18.15.0/node-v18.15.0.tar.gz --2023-04-06 17:24:47-- https://nodejs.org/dist/v18.15.0/node-v18.15.0.tar.gz Resolving nodejs.org (nodejs.org)... 104.20.23.46, 104.20.22.46, 2606:4700:10::6814:162e, ... Connecting to nodejs.org (nodejs.org)|104.20.23.46|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 85359314 (81M) [application/gzip] Saving to: ‘node-v18.15.0.tar.gz’ node-v18.15.0.tar.gz 100%[============================================================================>] 81.40M 8.99MB/s in 8.8s 2023-04-06 17:24:55 (9.28 MB/s) - ‘node-v18.15.0.tar.gz’ saved [85359314/85359314]
Step 4: Extract Files
After downloading the compressed package, you need to extract it by using tar -xzvf node-v18.15.0.tar.gz
command as shown below. This will create a local directory node-v18.15.0
and extract all the files in it.
cyberithub@ubuntu:~$ tar -xzvf node-v18.15.0.tar.gz
Step 5: Run Configure
Then you need to switch to the directory using cd node-v18.15.0
command and run the configure
script to verify all the system prerequisites required to install the package.
cyberithub@ubuntu:~$ cd node-v18.15.0/ cyberithub@ubuntu:~/node-v18.15.0$ ./configure Node.js configure: Found Python 3.8.10... INFO: configure completed successfully
Step 6: Compile the Code
In the next step, you need to compile the source code by running make
command as shown below. This will compile the code based on the rule specified in Makefile
. This step is going to take some time so you need to have little bit patience until all the code get compiled successfully.
cyberithub@ubuntu:~/node-v18.15.0$ make
make -C out BUILDTYPE=Release V=0
touch /home/cyberithub/node-v18.15.0/out/Release/obj.target/deps/googletest/gtest_prod.stamp
touch /home/cyberithub/node-v18.15.0/out/Release/obj.target/tools/icu/icu_implementation.stamp
touch /home/cyberithub/node-v18.15.0/out/Release/obj.target/tools/icu/icu_uconfig.stamp
touch /home/cyberithub/node-v18.15.0/out/Release/obj.target/tools/icu/icu_uconfig_target.stamp
g++ -o /home/cyberithub/node-v18.15.0/out/Release/obj.target/icuucx/deps/icu-small/source/common/ucnv_bld.o ../deps/icu-small/source/common/ucnv_bld.cpp '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_GLIBCXX_USE_CXX11_ABI=1' '-DNODE_OPENSSL_CONF_NAME=nodejs_conf' '-DNODE_OPENSSL_HAS_QUIC' '-DICU_NO_USER_DATA_OVERRIDE' '-D__STDC_FORMAT_MACROS' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DU_COMMON_IMPLEMENTATION=1' '-DU_ATTRIBUTE_DEPRECATED=' '-DU_STATIC_IMPLEMENTATION=1' '-DUCONFIG_NO_SERVICE=1' '-DU_ENABLE_DYLOAD=0' '-DU_HAVE_STD_STRING=1' '-DUCONFIG_NO_BREAK_ITERATION=0' -I../deps/icu-small/source/common -pthread -Wall -Wextra -Wno-unused-parameter -m64 -Wno-deprecated-declarations -Wno-strict-aliasing -O3 -fno-omit-frame-pointer -fno-exceptions -std=gnu++17 -frtti -MMD -MF /home/cyberithub/node-v18.15.0/out/Release/.deps//home/cyberithub/node-v18.15.0/out/Release/obj.target/icuucx/deps/icu-small/source/common/ucnv_bld.o.d.raw -c
g++ -o /home/cyberithub/node-v18.15.0/out/Release/obj.target/icuucx/deps/icu-small/source/common/loclikely.o ../deps/icu-small/source/common/loclikely.cpp '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_GLIBCXX_USE_CXX11_ABI=1' '-DNODE_OPENSSL_CONF_NAME=nodejs_conf' '-DNODE_OPENSSL_HAS_QUIC' '-DICU_NO_USER_DATA_OVERRIDE' '-D__STDC_FORMAT_MACROS' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DU_COMMON_IMPLEMENTATION=1' '-DU_ATTRIBUTE_DEPRECATED=' '-DU_STATIC_IMPLEMENTATION=1' '-DUCONFIG_NO_SERVICE=1' '-DU_ENABLE_DYLOAD=0' '-DU_HAVE_STD_STRING=1' '-DUCONFIG_NO_BREAK_ITERATION=0' -I../deps/icu-small/source/common -pthread -Wall -Wextra -Wno-unused-parameter -m64 -Wno-deprecated-declarations -Wno-strict-aliasing -O3 -fno-omit-frame-pointer -fno-exceptions -std=gnu++17 -frtti -MMD -MF /home/cyberithub/node-v18.15.0/out/Release/.deps//home/cyberithub/node-v18.15.0/out/Release/obj.target/icuucx/deps/icu-small/source/common/loclikely.o.d.raw -c
g++ -o /home/cyberithub/node-v18.15.0/out/Release/obj.target/icuucx/deps/icu-small/source/common/edits.o ../deps/icu-small/source/common/edits.cpp '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_GLIBCXX_USE_CXX11_ABI=1' '-DNODE_OPENSSL_CONF_NAME=nodejs_conf' '-DNODE_OPENSSL_HAS_QUIC' '-DICU_NO_USER_DATA_OVERRIDE' '-D__STDC_FORMAT_MACROS' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DU_COMMON_IMPLEMENTATION=1' '-DU_ATTRIBUTE_DEPRECATED=' '-DU_STATIC_IMPLEMENTATION=1' '-DUCONFIG_NO_SERVICE=1' '-DU_ENABLE_DYLOAD=0' '-DU_HAVE_STD_STRING=1' '-DUCONFIG_NO_BREAK_ITERATION=0' -I../deps/icu-small/source/common -pthread -Wall -Wextra -Wno-unused-parameter -m64 -Wno-deprecated-declarations -Wno-strict-aliasing -O3 -fno-omit-frame-pointer -fno-exceptions -std=gnu++17 -frtti -MMD -MF /home/cyberithub/node-v18.15.0/out/Release/.deps//home/cyberithub/node-v18.15.0/out/Release/obj.target/icuucx/deps/icu-small/source/common/edits.o.d.raw -c
g++ -o /home/cyberithub/node-v18.15.0/out/Release/obj.target/icuucx/deps/icu-small/source/common/ucurr.o ../deps/icu-small/source/common/ucurr.cpp '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_GLIBCXX_USE_CXX11_ABI=1' '-DNODE_OPENSSL_CONF_NAME=nodejs_conf' '-DNODE_OPENSSL_HAS_QUIC' '-DICU_NO_USER_DATA_OVERRIDE' '-D__STDC_FORMAT_MACROS' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DU_COMMON_IMPLEMENTATION=1' '-DU_ATTRIBUTE_DEPRECATED=' '-DU_STATIC_IMPLEMENTATION=1' '-DUCONFIG_NO_SERVICE=1' '-DU_ENABLE_DYLOAD=0' '-DU_HAVE_STD_STRING=1' '-DUCONFIG_NO_BREAK_ITERATION=0' -I../deps/icu-small/source/common -pthread -Wall -Wextra -Wno-unused-parameter -m64 -Wno-deprecated-declarations -Wno-strict-aliasing -O3 -fno-omit-frame-pointer -fno-exceptions -std=gnu++17 -frtti -MMD -MF /home/cyberithub/node-v18.15.0/out/Release/.deps//home/cyberithub/node-v18.15.0/out/Release/obj.target/icuucx/deps/icu-small/source/common/ucurr.o.d.raw -c
.................................................................
Step 7: Install Node.js
After successful compilation, you need to install the object file generated using sudo make install
command as shown below. If everything goes well then this will finally install Node.js package in your system.
cyberithub@ubuntu:~/node-v18.15.0$ sudo make install
make -C out BUILDTYPE=Release V=0
touch 37d6d0f61b90d9ff4d5b993f0589ae794358a362.intermediate
LD_LIBRARY_PATH=/home/cyberithub/node-v18.15.0/out/Release/lib.host:/home/cyberithub/node-v18.15.0/out/Release/lib.target:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; cd ../.; mkdir -p /home/cyberithub/node-v18.15.0/out/Release/obj/gen/src/node/inspector/protocol; /usr/bin/python3.8 tools/inspector_protocol/code_generator.py --jinja_dir tools/inspector_protocol --output_base "/home/cyberithub/node-v18.15.0/out/Release/obj/gen/src/" --config src/inspector/node_protocol_config.json
touch 533b4262ad6f02ad9df57d22ea505d81817c8cae.intermediate
LD_LIBRARY_PATH=/home/cyberithub/node-v18.15.0/out/Release/lib.host:/home/cyberithub/node-v18.15.0/out/Release/lib.target:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; cd ../tools/v8_gypfiles; mkdir -p /home/cyberithub/node-v18.15.0/out/Release/obj/gen/torque-generated/src/objects /home/cyberithub/node-v18.15.0/out/Release/obj/gen/torque-generated/src/wasm /home/cyberithub/node-v18.15.0/out/Release/obj/gen/torque-generated/src/ic /home/cyberithub/node-v18.15.0/out/Release/obj/gen/torque-generated /home/cyberithub/node-v18.15.0/out/Release/obj/gen/torque-generated/test/torque /home/cyberithub/node-v18.15.0/out/Release/obj/gen/torque-generated/third_party/v8/builtins /home/cyberithub/node-v18.15.0/out/Release/obj/gen/torque-generated/src/builtins /home/cyberithub/node-v18.15.0/out/Release/obj/gen/torque-generated/src/debug; "/home/cyberithub/node-v18.15.0/out/Release/torque" -o "/home/cyberithub/node-v18.15.0/out/Release/obj/gen/tor
..............................................................
Step 8: Check Version
After successful installation, you can check the installed version by using node --version
command as shown below.
cyberithub@ubuntu:~/node-v18.15.0$ node --version v18.15.0
It worked after me trying so many options. Thank you so much, I am grateful to have found this.
make command is taking to much time
How long did it take?
1 hour for me. its crazy.
For me, it took more than 3 hours.
Would you believe me when I said that the process didn't finish in 13 hours? But it happened.
It will depend on our system configuration.
This has been running all night, no end in sight?
Kindly have patience. It has lot of source files to compile.
thanks man, it was so useful for me.
it took more than 17+ hours, key is your screen should not be locked, try avoid keeping overnight