说明

cenos7 安装 node

准备工作

wget

如果已经安装,则可以跳过。

  [plaintext]
1
yum install -y wget

找到需要的版本

https://nodejs.org/en/download/

比如:https://nodejs.org/dist/v16.13.1/node-v16.13.1.tar.gz

安装

下载

  [plaintext]
1
$ wget https://nodejs.org/dist/v16.13.1/node-v16.13.1-linux-x64.tar.xz

解压

  [plaintext]
1
2
$ xz -d node-v16.13.1-linux-x64.tar.xz $ tar -xf node-v16.13.1-linux-x64.tar

我的目录信息如下:

  [plaintext]
1
2
3
4
5
# pwd /root/tool/nodejs # ls node-v16.13.1-linux-x64 node-v16.13.1-linux-x64.tar

配置

配置 node 和 npm。

  [plaintext]
1
2
sudo ln -s /root/tool/nodejs/node-v16.13.1-linux-x64/bin/node /usr/bin/node sudo ln -s /root/tool/nodejs/node-v16.13.1-linux-x64/bin/npm /usr/bin/npm

版本确认

  [plaintext]
1
2
3
4
5
# node -v v16.13.1 # npm -v 8.1.2

cnpm

因为国内网络问题,设置淘宝镜像。

https://npmmirror.com/

安装

  [plaintext]
1
$ npm install -g cnpm --registry=https://registry.npmmirror.com

软连接

安装之后你会发现用 cnpm 命令会提示找不到,要建立软链接

  [plaintext]
1
sudo ln -s /root/tool/nodejs/node-v16.13.1-linux-x64/bin/cnpm /usr/bin/cnpm

版本确认

  [plaintext]
1
2
3
4
5
6
7
8
# cnpm -v cnpm@7.1.0 (/root/tool/nodejs/node-v16.13.1-linux-x64/lib/node_modules/cnpm/lib/parse_argv.js) npm@6.14.15 (/root/tool/nodejs/node-v16.13.1-linux-x64/lib/node_modules/cnpm/node_modules/npm/lib/npm.js) node@16.13.1 (/root/tool/nodejs/node-v16.13.1-linux-x64/bin/node) npminstall@5.3.1 (/root/tool/nodejs/node-v16.13.1-linux-x64/lib/node_modules/cnpm/node_modules/npminstall/lib/index.js) prefix=/root/tool/nodejs/node-v16.13.1-linux-x64 linux x64 3.10.0-1160.45.1.el7.x86_64 registry=https://registry.npmmirror.com

参考资料

CentOS7安装NodeJS

Linux 下面解压.tar.gz 和.gz文件解压的方式

CentOS7 安装 node

Centos7 安装 Nodejs

https://nodejs.org/en/download/package-manager/#centos-fedora-and-red-hat-enterprise-linux

http://www.manongjc.com/article/56930.html