Use node 18/20 on CentOS 7

how to use node 18/20 on centos7

install node by nvm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

# install node
nvm ls-remote --lts

# node 16 is lts/gallium, node 20 is lts/iron
nvm install lts/gallium
nvm install lts/iron

# check node version
nvm alias default lts/gallium
node -v

nvm alias default lts/iron
node -v

You will find that node 16 works well, but node 20 will not work, because the glibc version is too low.
That's so bad, but don't worry; we can fix it by the following steps.

install glibc 2.31 and libstdc++.so.6.0.25

Follow my another article centos7-upgrade-libc to upgrade glibc to 2.31.

test

1
2
nvm alias default lts/iron
node -v # it works well