官方在Github上的文档:NodeSource Node.js Binary Distributions
目前的最新版本为Node.js v18.x不支持Centos 7系统,因此安装支持Centos 7 的最高版本Nodejs v16.x。
- 下载官方源:
# As root
curl -fsSL https://rpm.nodesource.com/setup_16.x | bash -
# No root privileges
curl -fsSL https://rpm.nodesource.com/setup_16.x | sudo bash -
- 安装
# 安装
yum install -y nodejs
# 验证安装结果
node -v
# v16.17.1
npm version
{
npm: '8.19.2',
node: '16.17.1',
v8: '9.4.146.26-node.22',
uv: '1.43.0',
zlib: '1.2.11',
brotli: '1.0.9',
ares: '1.18.1',
modules: '93',
nghttp2: '1.47.0',
napi: '8',
llhttp: '6.0.9',
openssl: '1.1.1q+quic',
cldr: '41.0',
icu: '71.1',
tz: '2022a',
unicode: '14.0',
ngtcp2: '0.1.0-DEV',
nghttp3: '0.1.0-DEV'
}