一、安装包不存在
[root@localhost ~]# yum install -y node
No package node available.
Error: Nothing to do
解决方案:
[root@localhost ~]# yum search node
[root@localhost ~]# yum install -y npm
[root@localhost ~]# node -v
v6.17.1
二、、在这里可以查看全部版本及各种环境的安装文件
https://nodejs.org/dist/
三、把 v6.17.1 升级到 v8.17.0
1、安装n组件
[root@localhost ~]# npm install -g n
/usr/bin/n -> /usr/lib/node_modules/n/bin/n
/usr/lib
└── n@7.0.0
2、安装nodejs指定版本
[root@localhost ~]# n 8.17.0
安装效果
installing : node-v8.17.0
mkdir : /usr/local/n/versions/node/8.17.0
fetch : https://nodejs.org/dist/v8.17.0/node-v8.17.0-linux-x64.tar.xz
installed : v8.17.0 (with npm 6.13.4)
Note: the node command changed location and the old location may be remembered in your current shell.
old : /usr/bin/node
new : /usr/local/bin/node
To reset the command location hash either start a new shell, or execute PATH="$PATH"
说明:
(1)默认nodejs安装路径是 /usr/bin/node
(2)而n组件安装路径是 /usr/local/bin/node
3、编辑系统环境变量
[root@localhost ~]# vim /etc/profile
4、在配置文件最后加上环境变量内容
export N_PREFIX=/usr/local/n/versions/node/8.17.0/ #node实际安装位置
export PATH=$N_PREFIX/bin:$PATH
5、使配置的环境变量生效
[root@localhost ~]# source /etc/profile
6、查看当前版本
[root@localhost ~]# node -v
v8.17.0
7、其它
]# curl -sL https://rpm.nodesource.com/setup_8.x | bash -
[root@localhost ~]# yum install -y nodejs
[root@localhost ~]# npm -v
6.13.4
[root@localhost ~]# node -v
v8.17.0
未完,后续扩展!