143

I'm trying to install Nodejs on Amazon linux machine, I'm following this documentation to install node https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html but I'm getting below error when I execute this command nvm install node

How can I fix this issue? Any help would be much appreciated. Thanks!

v18.0.0 is already installed.
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)
nvm is not compatible with the npm config "prefix" option: currently set to ""
Run `nvm use --delete-prefix v18.0.0` to unset it.
[ec2-user@ip-xx-xxx-xx-xx ~]$ node -e "console.log('Running Node.js ' + process.version)"
-bash: node: command not found

I tried running this nvm use --delete-prefix v18.0.0 but no luck.

3
  • 4
    If the solution helped you, please consider marking as answer :)
    – Efren
    Commented May 3, 2022 at 7:05
  • it work if don't close terminal Commented May 23, 2023 at 11:24
  • Had a similar issue but on AWS lambda. After trying lots of things I ended up upgrading to node v 20 so to use Amazon Linux 2023 runtime. This solved my problem. docs.aws.amazon.com/lambda/latest/dg/…
    – Dhruv Pal
    Commented Apr 12 at 13:29

9 Answers 9

159

Try installing the active LTS version instead of latest with nvm install 16 (instead of nvm install node) as per the examples.

This was tested on the docker image amazonlinux:2 and correlates to what AWS CDK supports (ref)

Update

LTS has moved on for node, however, as per @djvg's comment, note there is a limitation with amazon linux 2 on glibc, so if requiring node > 16 will need to move to newer amazon linux version, eg: https://github.com/amazonlinux/amazon-linux-2023/blob/main/Release-Notes-Amazon-Linux-2022.0.20220728.0.md

10
  • 4
    I got this command to install the LTS version from AWS docs: nvm install --lts Commented Jul 12, 2022 at 16:19
  • 66
    This does not solve the issue for those who want to install node 18
    – Bilow
    Commented Oct 4, 2022 at 16:17
  • 3
    @Bilow the question was for AWS, so you may have to wait for 18, check the ref document link: We recommend a version in active long-term support, which, at this writing, is the latest 16.x release
    – Efren
    Commented Oct 6, 2022 at 2:32
  • 11
    node v18.12.0, which is the latest active lts at the time of this comment, also has this error on centos. Commented Oct 28, 2022 at 21:10
  • 13
    As mentioned elsewhere, the problem is caused by the fact that Amazon Linux 2 only supports glibc 2.26. For newer versions you'll probably need to migrate to Amazon LInux 2022.
    – djvg
    Commented Nov 25, 2022 at 15:17
49

It seems like you are using v.18.0.0 which was the latest but not well-supported.

Try uninstalling that.

nvm uninstall 18.0.0

Install a version that is active.

nvm install 16.0.0

You should now be using v16 which should be well-supported.

1
  • 14
    This does not solve the issue for those who want to install node v18
    – aksyuma
    Commented Jun 10, 2023 at 12:36
29

The error message:

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)

is telling you that you do not have a new enough version of glibc for nvm to install node 18. The error tells you it requires at least glibc 2.27.

You can find your current glibc version with: ldd --version

It's possible that you can install a newer version of glibc using a package manager like apt-get.

You can find the latest available version of glibc available via your package manager with: apt-cache policy libc6.

If your package manager can't install a new-enough version of glibc, you need to be on a newer version of your operating system. In Ubuntu, you can accomplish an OS upgrade with do-release-upgrade.

1
  • 1
    and because the question is about Amazon Linux, if you want to go from Node 16 to Node 18 and above, you need to start using a newer version of GLIBC, which is not available on Amazon Linux 2 = you need to move to Amazon Linux 2023
    – Pierre
    Commented Nov 9, 2023 at 0:45
26

Amazon Linux 2 or some os includes glibc 2.26 or under. To use a higher glib version, you need to consider other AMI. for example) Amazon Linux 2022. (al2022-ami) it includes glibc 2.34

reference : https://repost.aws/questions/QUrXOioL46RcCnFGyELJWKLw/glibc-2-27-on-amazon-linux-2

2
  • 2
    More about Amazon Linux 2022
    – djvg
    Commented Nov 25, 2022 at 14:55
  • 1
    Honestly, this is the real answer, as much as no one wants to hear it. If you need to be running a newer version of Node, you need to run a host that supports it. The other answers just stating you should downgrade to an older Node are not really answers at all.
    – bsplosion
    Commented Dec 4, 2023 at 19:26
2

In My scenario it's OS issue. OS need to upgraded:

My Current OS version is: Red Hat Enterprise Linux Server 7.9 (Maipo)

cat /etc/os-release

I got below issue for node-18 install

    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)

Check ldd version as above issue

ldd --version

Upgraded OS version with: Red Hat Enterprise Linux 8.2 (Ootpa) and issue got resolved.

ldd version should be more than ldd (GNU libc) 2.27

0

👋

Ran into a bit of a snag while working through the AWS tutorial on spinning up a React app with Amplify and GraphQL. Thought I'd share the hiccup and the fix, just in case anyone else finds themselves in the same boat.

The Issue: GLIBC Error: If you're like me and went with Node.js v18 (because why not, right?), you might hit a GLIBC_2.27 not found error during the Amplify build process. Turns out, the AWS Amplify build environment isn't quite on board with Node.js v18 due to some GLIBC version mismatches.

Package Compatibility: So, the obvious move is to dial back Node.js to an earlier version, but here's the kicker - doing that breaks [email protected] because it's expecting Node.js v18. You get slapped with an "incompatible engine" error, and you're back to square one.

The Fix: After a bit of tinkering, I landed on a setup that works. Here's the amplify.yml that finally got things rolling:

version: 1
backend:
  phases:
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - amplifyPush --simple
frontend:
  phases:
    preBuild:
      commands:
        - nvm install 17.9.1 # Rolling back to Node.js v17.9.1
        - nvm use 17.9.1
        - npm install -g yarn # Still gotta have my yarn!
        - yarn install --ignore-engines # This is the game-changer
    build:
      commands:
        - nvm use 17.9.1
        - yarn run build
  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

Dropped down to Node.js 17.9.1 to sidestep the GLIBC drama. Slapped on --ignore-engines with yarn install to keep react-hook-form happy without it fussing over the Node version. Hope this saves you a headache or two. Happy coding!

0

This (credits) worked for me on node 18:

  • Go to AWS Amplify
  • From the side menu, under App settings, select Build settings
  • On the page, scroll down to Build image settings
  • Click Edit, an Edit build image settings modal will show up.
  • Under Build image section, click on dropdown and select Build image
  • Paste public.ecr.aws/docker/library/node:18.17.0 in Reference build image input (Note: Other than node version 18.17.0, you can also search for specific version of node on https://gallery.ecr.aws/docker/library/node)
0

I've followed these steps and resolved the issue:

# Download the Node.js binary (x86 only)
wget -nv https://d3rnber7ry90et.cloudfront.net/linux-x86_64/node-v18.17.1.tar.gz

# Create the directory for Node.js
mkdir -p /usr/local/lib/node

# Extract the Node.js tarball
tar -xf node-v18.17.1.tar.gz

# Move Node.js to the proper directory
mv node-v18.17.1 /usr/local/lib/node/nodejs

# Unload NVM and set the new Node.js in the PATH
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 the environment variables
source /home/ec2-user/.bashrc

# Verify that Node.js v18.x is operating
node -e "console.log('Running Node.js ' + process.version)"
-2

There is some issue with nvm latest version 18.x.x.

Try following steps to resolve the issue

1.Uninstall your nvm

$ nvm uninstall <nvm_version>

ie. $ nvm uninstall 18.12.2

2.Install stable version of nvm

$ nvm install <stable_nvm_version>

ie. $ nvm install 16.0.0

Not the answer you're looking for? Browse other questions tagged or ask your own question.