node: /lib64/libc.so.6: version GLIBC not found after nvm install
node: /lib64/libc.so.6: version `GLIBC_2.27' not found (required by node)Short answer
The Node.js binary was built against a newer glibc than the one on the server. Amazon Linux 2 ships glibc 2.26, and current official Node.js binaries need glibc 2.34 or newer. Move the instance to Amazon Linux 2023, which ships 2.34, or compile Node.js on the machine with nvm install -s.
Fix it fast
1Find out which cause you have
Print the OS release and the glibc version on the server. Compare the glibc number with what the Node.js version you installed needs.
cat /etc/os-release ldd --version | head -n 12Match what you see, then jump to its fix
What does the error look like?
node: /lib64/libc.so.6: version `GLIBC_2.27' not found (required by node)
Cause 1 of 2
The operating system is older than the Node.js binary supports
1Check
Amazon documents glibc 2.26 for Amazon Linux 2 and 2.34 for Amazon Linux 2023. The Node.js project lists glibc 2.34 or newer as the minimum for its official Linux x64 and arm64 builds.
ldd --version | head -n 1
node --version2Fix
Launch a new instance from an Amazon Linux 2023 image, move the app there, and install Node.js again with nvm.
nvm install --lts3Verify
Check that node starts and prints its version.
node --version
ldd --version | head -n 1Confirmed by docs.aws.amazon.com
Cause 2 of 2
You cannot change the OS yet, and the prebuilt binary does not fit
1Check
nvm downloads prebuilt binaries by default. Its README says the -s flag makes nvm download the Node.js source and compile it locally, and recommends it when official binaries do not work because of shared library incompatibilities.
nvm --version2Fix
Install a C++ toolchain, then compile on the server. It takes a long time, and AWS lists gcc 7.3 for Amazon Linux 2, so check the compiler a Node.js line needs in its BUILDING.md first. Treat this as a bridge until you can move to Amazon Linux 2023.
nvm install -s --lts3Verify
Run node and check the version.
node --versionConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Check the glibc version of a base image before choosing a Node.js major version.
- Pick Amazon Linux 2023 for new EC2 instances.
- Set an nvm default alias so every new shell uses the version you tested.
- Read the platform table in the Node.js build notes when you upgrade the Node.js major version.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
A binary built in one image will not start in another because of glibc
/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./app)
The binary was linked against a newer glibc than the image it now runs in.
3 causes, each with a fixServers
Azure App Service on Linux restarts the container and the site never starts
The container restarts again and again and the site returns an application error
App Service sends a warmup request to the container and restarts it if no HTTP answer comes back in time.
5 causes, each with a fixServers
Cypress says the npm package is installed but the binary is missing
Cypress binary is missing after npm install in CI or in a Docker build
The npm package is only a launcher.
3 causes, each with a fixServers
A native Node.js module fails on AWS Lambda with invalid ELF header
Error: /var/task/node_modules/<package>/build/Release/<name>.node: invalid ELF header
Lambda loads native addons on Linux, so a .node file built on macOS or Windows is not a valid Linux ELF file there.
3 causes, each with a fixServers
nginx 502 Bad Gateway in front of a Node.js app
connect() failed (111: Connection refused) while connecting to upstream
A 502 means nginx reached for your Node.js app and got nothing usable back.
5 causes, each with a fixServers
nginx gives up waiting for the app and returns 504
upstream timed out (110: Connection timed out) while reading response header from upstream
nginx returns 504 when the app behind it takes the request but sends nothing back within proxy_read_timeout (60 seconds by default), or when the connection cannot be opened in time.
5 causes, each with a fix