Installing Node.js 18+ on CentOS 7: Fix glibc Compatibility Issue

Recently I had to install node 18 on an old CentOS 7 machine. Upgrading was not possible. Considering node 18 is relatively old, I didn’t expect any issues.

Turns out, node 18+ is not officially supported in CentOS 7.

CentOS 7 doesn’t have the necessary glibc library version for me to install newer node versions. If you try to install node 18 you get the following error:

node: /lib64/libm.so.6: version GLIBC_2.27 not found (required by node)
node: /lib64/libc.so.6: version GLIBC_2.25 not found (required by node)
node: /lib64/libc.so.6: version GLIBC_2.28 not found (required by node)
node: /lib64/libstdc++.so.6: version CXXABI_1.3.9 not found (required by node)
node: /lib64/libstdc++.so.6: version GLIBCXX_3.4.20 not found (required by node)
node: /lib64/libstdc++.so.6: version GLIBCXX_3.4.21 not found (required by node)

https://unofficial-builds.nodejs.org/ provides binary versions of Node that don’t require compilation. We can use this to get new versions that are compatible with older glibc versions.

I like using nvm for managing my node installations, but you can use any other manager or do a manual installation.

Update the nvm configuration in .bashrc

  • Open ~/.bashrc and add the following after the NVM_DIR lines:
# Enable binary node install
export NVM_NODEJS_ORG_MIRROR=https://unofficial-builds.nodejs.org/download/release # Set up unofficial builds
nvm_get_arch() { nvm_echo x64-glibc-217; } # Needed to build the download URL
  • After the change you should have the following 6 lines present:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

# Enable binary node install
export NVM_NODEJS_ORG_MIRROR=https://unofficial-builds.nodejs.org/download/release # Set up unofficial builds
nvm_get_arch() { nvm_echo x64-glibc-217; } # Needed to build the download URL
  • Restart/quit terminal or do source ~/.bash_profile for changes to apply.

Install Node

Here’s an example using node 18.19.1, but you can use any binary version present in the unofficial builds (node 20, node 22).

nvm install 18.19.1
nvm use 18
nvm alias default 18

Confirm that the build works

Navigate to your project folder and run:

npm i

If npm install passes without any errors, proceed with a regular build to confirm that the compiled version works.


Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.