Skip to content

GLIBC_2.27 Not Found on Amazon EC2

Problem Overview

When attempting to install or run Node.js on Amazon Linux EC2 instances, users frequently encounter the error:

node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node)

This occurs because newer versions of Node.js (v18+) require a more recent version of the GNU C Library (glibc) than what's available on Amazon Linux 2.

Root Cause

Amazon Linux 2 ships with glibc 2.26, while Node.js v18+ requires at least glibc 2.27. You can check your current glibc version with:

bash
ldd --version

Solutions

Quick Fix

The simplest solution is to install a compatible Node.js version that works with Amazon Linux 2's glibc.

bash
# Uninstall problematic version if already installed
nvm uninstall 18.0.0

# Install Node.js 16 (LTS version compatible with AL2)
nvm install 16
nvm use 16

Option 2: Use GLIBC-Compatible Unofficial Builds

For newer Node.js versions on Amazon Linux 2, use unofficial builds specifically compiled with older glibc versions:

bash
# Download a glibc-compatible build (example for v22.17.1)
wget -nv https://unofficial-builds.nodejs.org/download/release/v22.17.1/node-v22.17.1-linux-x64-glibc-217.tar.gz

# Extract and install
mkdir -p /usr/local/lib/node
tar -xf node-v22.17.1-linux-x64-glibc-217.tar.gz
mv node-v22.17.1-linux-x64-glibc-217 /usr/local/lib/node/nodejs

# Update environment variables
echo "export NVM_DIR=''" >> /home/ec2-user/.bashrc
echo "export NODEJS_HOME=/usr/local/lib/node/nodejs" >> /home/ec2-user/.bashrc
echo "export PATH=\$NODEJS_HOME/bin:\$PATH" >> /home/ec2-user/.bashrc

# Reload environment
source /home/ec2-user/.bashrc

Option 3: Upgrade to Amazon Linux 2023

Amazon Linux 2023 includes glibc 2.34, which supports all modern Node.js versions:

Production Consideration

Migrating to a new OS version requires thorough testing of your applications and infrastructure.

bash
# Check current OS version
cat /etc/os-release

# Consider migrating to Amazon Linux 2023
# This may require creating a new EC2 instance

Option 4: Use AWS-Amplify Specific Solution

For AWS Amplify builds, specify a compatible Node.js Docker image:

  1. Navigate to AWS Amplify → App settings → Build settings
  2. Under Build image settings, select "Edit"
  3. Choose "Build image" and enter:
    public.ecr.aws/docker/library/node:18.17.0

Option 5: Install via Homebrew

bash
# Install Homebrew on Linux
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install Node.js via Homebrew
brew install node

# Add to your shell profile (~/.bashrc or ~/.zshrc)
echo 'export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Verification

After applying any solution, verify your Node.js installation:

bash
node --version
node -e "console.log('Running Node.js ' + process.version)"

Best Practices

  1. Check compatibility before installing new Node.js versions on Amazon Linux 2
  2. Use LTS versions (Node.js 16) for maximum stability on AL2
  3. Consider OS upgrade to Amazon Linux 2023 for long-term compatibility
  4. Test thoroughly after making changes to production environments

Warning

Avoid manually upgrading glibc on production systems as it may break system dependencies and cause instability.

Troubleshooting

If you continue to experience issues:

  1. Check your glibc version: ldd --version
  2. Verify NVM configuration: nvm ls
  3. Ensure PATH variables are correctly set: echo $PATH
  4. Check for multiple Node.js installations: which node

For ongoing compatibility issues, consider using Docker containers with specified base images to control the underlying system dependencies.