How to solve issues when installing NodeJS 18.15.0

Problem

When running node -v I get the following error:

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

Analysis

I ran:

terminator@skynet1:/usr/local/lib/nodejs# ldd --version
ldd (Debian GLIBC 2.24-11+deb9u4) 2.24
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

In another machine in which this problem doesn't exist I get the following result:

terminator@skynet2:/usr/local/lib/nodejs# ldd --version
ldd (Debian GLIBC 2.28-10) 2.28
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

It seems that the problem could be solved by updating GLIBC which makes more sense than downgrading the NodeJS version (as everyone says on the Internet). I found a link (listed below) with a very good analysis of the situation. The author mentions that such errors happen when the node binaries are built on GLIBC-2.28 or more recent system. It makes total sense to me.

Solution

Install the latest version of GLIBC:

sudo apt-get install libc6

After that I tried again to run node -v and it worked:

terminator@skynet1:/usr/local/lib/nodejs# node -v
v18.15.0

I double-checked the GLIBC version and it was succesfully updated.

terminator@skynet1:/usr/local/lib/nodejs# ldd --version
ldd (Debian GLIBC 2.28-10+deb10u1) 2.28
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

Other Problems

I actually faced a situation in which I couldn't update the machines with the command given above, I got this error:

terminator@skynet5:/usr/local/lib/nodejs# apt-get install libc6
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libc6 is already the newest version (2.24-11+deb9u4).
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.

The shit was telling me that 2.24 was already the most recent but I know it's not so I ran the following command in the affected machine:

terminator@skynet5:/usr/local/lib/nodejs# hostnamectl
   Static hostname: skynet5
         Icon name: computer-vm
           Chassis: vm
        Machine ID: cba6300000049e5a7e7ebdabababa086
           Boot ID: abcab1555554ee872354363463434569
    Virtualization: vmware
  Operating System: Debian GNU/Linux 9 (stretch)
            Kernel: Linux 4.9.0-8-amd64
      Architecture: x86-64

Which shows that I am using Debian 9. Therefore I need to know what is the maximum version of GLIBC that I can install in that operating system, so to know that I ran the following command:

terminator@skynet5:/usr/local/lib/nodejs# apt-cache policy libc6
libc6:
  Installed: 2.24-11+deb9u4
  Candidate: 2.24-11+deb9u4
  Version table:
 *** 2.24-11+deb9u4 500
        500 http://1.2.3.4/packages/mirror/deb.debian.org/debian stretch/main amd64 Packages
        100 /var/lib/dpkg/status
     2.24-11+deb9u1 500
        500 http://security.debian.org/debian-security stretch/updates/main amd64 Packages

That tells me that the maximum version I can install is 2.24, so the solution to this is to update Debian to version 10. I know it works because my other machines are Debian 10 and I don't have that problem.

Sources: