Install Node Ubuntu

Retrofitting Node 20 in Ubuntu 18 LTS

One of the hardest parts of system administration is keeping systems updated and secure. However, when an upgrade is not feasible but application support is needed, there’s often no choice but to retrofit the necessary dependencies. This may involve tinkering with the system, patching, or using custom configurations to ensure the application works without breaking other systems or the OS itself.

In this guide, we will explore how to install Node.js 20 on Ubuntu 18.04 LTS, along with npm 10, using Node Version Manager (NVM) to streamline the process. By retrofitting Node.js 20 on an older version of Ubuntu, we can ensure compatibility without the need for a full OS upgrade, which may not always be practical in production environments.

To ease up things and to have less headache we will be using NVM (Node Version Manager) to make it easier to install node and npm.

To ease things up, NVM will help manage the Node.js and npm versions required, making the installation smoother and reducing the potential for conflicts.

Why on Ubuntu 18.04?

As applications evolve, newer versions of tools like Node.js introduce better performance, enhanced security features, and new functionality. However, upgrading the entire operating system to support the latest versions isn’t always an option, especially in cases where legacy applications or system constraints exist. Ubuntu 18.04 LTS, being a stable and widely-used release, may still be part of many production systems. This guide helps maintain compatibility by retrofitting Node.js 20 into your environment without breaking other dependencies.

Now, let’s dive into retrofitting on Ubuntu 18.04.3 LTS.

What You Need

Before we get started, here are a few things you will need

  • Root access on your system
  • Node
  • NPM
  • Some essential build tools like make, gcc, and bison

Run the following commands to install the necessary build tools and dependencies

sudo apt-get install g++ make gcc bison patchelf
wget -c https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz
tar -zxf glibc-2.28.tar.gz
cd glibc-2.28
mkdir glibc-build && cd glibc-build
../configure --prefix=/opt/glibc-2.28
make && make install
patchelf --set-interpreter /opt/glibc-2.28/lib/ld-linux-x86-64.so.2 --set-rpath /opt/glibc-2.28/lib/:/lib/x86_64-linux-gnu/:/usr/lib/x86_64-linux-gnu/ /root/.nvm/versions/node/v20.12.2/bin/node

This will fix the following issue

node: /lib/x86_64-linux-gnu/libc.so.6: version 'GLIBC_2.28' not found (required by node)

Conclusion

By following these steps, you can successfully retrofit . Using NVM simplifies managing versions, and the manual GLIBC patch ensures compatibility without the need for a full OS upgrade. This approach allows you to keep your system stable while still using the latest version of Node.js for your applications.