1

I can say I went through all Google results regarding this, but no one works. The GNU libc version is very old:
ldd (GNU libc) 2.17.

Trying version up to nodesource 8.x all installations fails because of the old GNU libc:

Error: Package: 2:nodejs-19.9.0-1nodesource.x86_64 (nodesource)
           Requires: libm.so.6(GLIBC_2.27)(64bit)
Error: Package: 2:nodejs-19.9.0-1nodesource.x86_64 (nodesource)
           Requires: libc.so.6(GLIBC_2.28)(64bit)

What can I do? Would it help when I try to build node from the source with gcc-c++? Reading the requirements I doubt this will work because Centos 7 has also a very old gcc version which is not supported anymore, or am I wrong?

Any hints?

5
  • serverfault.com/questions/894625/… Commented Jun 14, 2023 at 8:19
  • @K-att- I don't really think this is the solution. The way how to fix it in the link you provided is for programs which fail to run due to wrong glibc version. In my case I CANNOT install a program because the system glibc is too old. Therefore I would have to provide yum the path to the newer glibc and how to do it? Commented Jun 14, 2023 at 8:52
  • I think the safe way is to upgrade to OL8. Patched centos 7 => file /usr/lib/libm.so.6 /usr/lib/libm.so.6: symbolic link to libm-2.17.so' Ol8 => file /usr/lib64/libm.so.6 /usr/lib64/libm.so.6: symbolic link to libm-2.28.so Commented Jun 14, 2023 at 9:25
  • @K-attila- This is a hosted server with Plesk. I don't think I can do it as the hoster doesn't provide OL8. I can install a new server with Ubuntu 22.04 and I think, I will invest in the holidays few days to install the new server and migrate the existing one. Centos 7 is anyway close to the EOL. Commented Jun 14, 2023 at 11:06
  • 1
    Yes, it is a good solution, too. You can hack the Centos, but why_ Commented Jun 14, 2023 at 11:40

2 Answers 2

0

I got it work:

  1. cloning it from Github - V19.9.0
  2. Installing C++ 11
  3. Setting the proper export variables for configure
  4. Compiling and installing it.
  5. This are now the installed versions:
root@server:/usr/local/src/node => npm version
{

  npm: '9.6.3',
  node: '19.9.0',
  acorn: '8.8.2',
  ada: '1.0.4',
  ares: '1.19.0',
  brotli: '1.0.9',
  cldr: '42.0',
  icu: '72.1',
  llhttp: '8.1.0',
  modules: '111',
  napi: '8',
  nghttp2: '1.52.0',
  nghttp3: '0.7.0',
  ngtcp2: '0.8.1',
  openssl: '3.0.8+quic',
  simdutf: '3.2.3',
  tz: '2023c',
  undici: '5.21.0',
  unicode: '15.0',
  uv: '1.44.2',
  uvwasi: '0.0.16',
  v8: '10.8.168.25-node.16',
  zlib: '1.2.13'
}

root@server:~ => cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)

root@server:~ => ldd --version
ldd (GNU libc) 2.17
Copyright (C) 2012 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.
0

How to run node v20.x on CentOs 7.9?

This approach is similar to https://stackoverflow.com/questions/72921215/getting-glibc-2-28-not-found/77247394#77247394 and https://serverfault.com/questions/894625/safely-upgrade-glibc-on-centos-7/894689#894689 but for CentOS@^7.

Taking the current LTS version of node@^22 that requires [email protected] since node@^18 as example:

  1. Install pre-built [email protected] from centos-release-scl:

    yum install centos-release-scl
    yum install devtoolset-8-{gcc,make}
    
  2. Enter the subshell with [email protected]

    scl enable devtoolset-8 # enter scl subshell
    which gcc # /opt/rh/devtoolset-8/root/usr/bin/gcc
    gcc --version # gcc version 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC)
    
  3. Grab the source of [email protected]:

    wget https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.xz
    tar xvf glibc-2.28.tar.xz
    
  4. Build the [email protected]:

    cd glibc-2.28
    mkdir build
    cd build
    
    ../configure --prefix=/opt/glibc-2.28
    time make -j"$(nproc)"
    make install
    exit # exit the scl subshell
    
  5. Grab the source of [email protected] for building its [email protected] as node@22 is requiring versionized symbol with GLIBCX_3.4.22:

    And according to https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html in https://stackoverflow.com/questions/44773296/libstdc-so-6-version-glibcxx-3-4-20-not-found/49363515#49363515 , the first version that exporting symbol version GLIBCX_3.4.22 is between [email protected] and [email protected] so we choose to build the latest [email protected] within its 6.x series

    wget https://ftp.gnu.org/gnu/gcc/gcc-6.5.0/gcc-6.5.0.tar.xz
    tar xvf gcc-6.5.0.tar.xz
    
    scl enable devtoolset-8 # enter scl subshell
    cd gcc-6.5.0
    mkdir build
    cd build
    
  6. It's possible to compile only the libstdc++.so.6 without build the whole GCC: How to compile libstdc++ with specific compiler option?

    ../libstdc++-v3/configure --prefix=/opt/libstdc++-6.0.22 --disable-multilib
    time make -j"$(nproc)"
    

    But the built artifact won't export symbol _ZSt11__once_call that Node is importing, this can be verified by

    strings src/.libs/libstdc++.so.6.0.22 | grep _ZSt11__once_call
    

    that outputs nothing: https://stackoverflow.com/questions/72405588/using-clang-with-built-libstdc-produces-undefined-symbol-zst15-once-callable

  7. So we'll still have to build the complete GCC collection:

    cd ..
    rm -rf build
    ./contrib/download_prerequisites
    
    mkdir build
    cd build
    ../configure --prefix=/opt/gcc-6.5.0 --disable-multilib
    
  8. Depend on the performance of your hardware, this may take hours and many GiBs of disk space: https://gcc.gnu.org/install/build.html

    time make -j"$(nproc)"
    cd x86_64-pc-linux-gnu/libstdc++-v3 # only install libstdc++.so
    make install
    exit # exit the scl subshell
    
  9. If you are in hurry and trusting some randomly uploaded binrary, extract the path gcc63-c++-6.3.0-1.el7.x86_64.cpio\.\usr\local\gcc63\lib64\libstdc++.so.6.0.22 from gcc63-c++-6.3.0-1.el7.x86_64.rpm that uploaded by https://stackoverflow.com/questions/47175706/how-to-install-gcc-4-9-2-on-rhel-7-4/47189915#47189915 and store it under /opt/glibc-2.28/lib/libstdc++.so.6.0.22.

    On Windows you may use NanaZip to unarchive *.rpm and *.cpio files.

  10. Symlinking the built libstdc++.so.6.0.22 under /opt/glibc-2.28/lib if you don't want to define a shell var LD_LIBRARY_PATH=/opt/gcc-6.5.0/lib64 node for everytime running node:

    ln -s /opt/gcc-6.5.0/lib64/libstdc++.so.6.0.22 /opt/glibc-2.28/lib/libstdc++.so.6
    
  11. Download binrary of patchelf for patching the node executable:

    wget https://github.com/NixOS/patchelf/releases/download/0.18.0/patchelf-0.18.0-x86_64.tar.gz
    tar xzvf patchelf-0.18.0-x86_64.tar.gz
    
  12. Download the node itself:

    wget https://nodejs.org/download/release/v22.12.0/node-v22.12.0-linux-x64.tar.xz
    tar xvf node-v22.12.0-linux-x64.tar.xz
    cd node-v22.12.0-linux-x64/bin
    
  13. Patch node:

    ~/patchelf/bin/patchelf --set-interpreter /opt/glibc-2.28/lib/ld-linux-x86-64.so.2 node # required
    ~/patchelf/bin/patchelf --set-rpath /opt/glibc-2.28/lib:/usr/lib64 node # optional, similar to 9.
    
  14. Enjoy:

    ./node
    console.log(1);
    process.exit(2);
    echo $?
    

Kickstart script:

# https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425
# https://mywiki.wooledge.org/BashFAQ/105
set -euxo pipefail

wget https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.xz
tar xvf glibc-2.28.tar.xz

yum install centos-release-scl
yum install devtoolset-8-{gcc,make}
scl enable devtoolset-8
    cd glibc-2.28
    mkdir build
    cd build

    ../configure --prefix=/opt/glibc-2.28
    make -j"$(nproc)"
    make install
exit

wget https://ftp.gnu.org/gnu/gcc/gcc-6.5.0/gcc-6.5.0.tar.xz
tar xvf gcc-6.5.0.tar.xz

scl enable devtoolset-8
    cd gcc-6.5.0
    ./contrib/download_prerequisites

    mkdir build
    cd build
    ../configure --prefix=/opt/gcc-6.5.0 --disable-multilib

    # depend on the performance of your hardware, this may take hours and many GiBs of disk space
    time make -j"$(nproc)"
    make install
exit

ln -s /opt/gcc-6.5.0/lib64/libstdc++.so.6.0.22 /opt/glibc-2.28/lib/libstdc++.so.6

wget https://github.com/NixOS/patchelf/releases/download/0.18.0/patchelf-0.18.0-x86_64.tar.gz
tar xzvf patchelf-0.18.0-x86_64.tar.gz

wget https://nodejs.org/download/release/v22.12.0/node-v22.12.0-linux-x64.tar.xz
tar xvf node-v22.12.0-linux-x64.tar.xz
cd node-v22.12.0-linux-x64/bin

# https://serverfault.com/questions/894625/safely-upgrade-glibc-on-centos-7/894689#894689
~/patchelf/bin/patchelf --set-interpreter /opt/glibc-2.28/lib/ld-linux-x86-64.so.2 node
~/patchelf/bin/patchelf --set-rpath /opt/glibc-2.28/lib:/usr/lib64 node

./node

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.