linux服务器快速卸载安装 node 环境

卸载旧的版本(没安装过忽略)

# 先卸载npm
sudo npm uninstall npm -g

# 卸载node
yum remove nodejs npm -y

看看是否有残留

进入 /usr/local/lib 删除所有 nodenode_modules 文件夹

进入 /usr/local/include 删除所有 nodenode_modules 文件夹

进入 /usr/local/bin 删除 node 的可执行文件

安装 node

http://nodejs.cn/download/

# 切换到要安装到的目录 /usr/local 
[root@VM-8-3-centos ~]# cd /usr/local
# 查看一下文件夹下的内容
[root@VM-8-3-centos local]# ls
bin  etc  games  include  lib  lib64  libexec  nginx  qcloud  sbin  share  soft  src  yd.socket.server
# 下载 node 安装包
[root@VM-8-3-centos local]# wget https://npm.taobao.org/mirrors/node/v16.11.1/node-v16.11.1-linux-x64.tar.xz
--2021-10-16 08:47:33--  https://npm.taobao.org/mirrors/node/v16.11.1/node-v16.11.1-linux-x64.tar.xz
Resolving npm.taobao.org (npm.taobao.org)... 114.55.80.225
Connecting to npm.taobao.org (npm.taobao.org)|114.55.80.225|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://cdn.npm.taobao.org/dist/node/v16.11.1/node-v16.11.1-linux-x64.tar.xz [following]
--2021-10-16 08:47:33--  https://cdn.npm.taobao.org/dist/node/v16.11.1/node-v16.11.1-linux-x64.tar.xz
Resolving cdn.npm.taobao.org (cdn.npm.taobao.org)... 183.61.241.230, 183.60.138.231, 14.215.172.222, ...
Connecting to cdn.npm.taobao.org (cdn.npm.taobao.org)|183.61.241.230|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 21615828 (21M) [application/x-xz]
Saving to: ‘node-v16.11.1-linux-x64.tar.xz’

100%[====================================================================================================================================================>] 21,615,828  24.1MB/s   in 0.9s

2021-10-16 08:47:34 (24.1 MB/s) - ‘node-v16.11.1-linux-x64.tar.xz’ saved [21615828/21615828]

# 再次查看一下文件夹下的内容, 发现已经有 node-v16.11.1-linux-x64.tar.xz
[root@VM-8-3-centos local]# ls
bin  etc  games  include  lib  lib64  libexec  nginx  node-v16.11.1-linux-x64.tar.xz  qcloud  sbin  share  soft  src  yd.socket.server
# 解压 xz
[root@VM-8-3-centos local]# xz -d node-v16.11.1-linux-x64.tar.xz

[root@VM-8-3-centos local]# ls
bin  etc  games  include  lib  lib64  libexec  nginx  node-v16.11.1-linux-x64.tar  qcloud  sbin  share  soft  src  yd.socket.server

# 解压 tar
[root@VM-8-3-centos local]# tar -xf node-v16.11.1-linux-x64.tar

[root@VM-8-3-centos local]# ls
bin  etc  games  include  lib  lib64  libexec  nginx  node-v16.11.1-linux-x64  node-v16.11.1-linux-x64.tar  qcloud  sbin  share  soft  src  yd.socket.server

# 添加到环境变量
[root@VM-8-3-centos local]# vim /etc/profile
...

# node 环境变量
export NODE_HOME=/usr/local/node-v16.11.1-linux-x64
export PATH=$NODE_HOME/bin:$PATH

:wq 保存并退出

# 使 环境变量生效
[root@VM-8-3-centos local]# source /etc/profile

# 检查是否安装完成
[root@VM-8-3-centos local]# node -v
v16.11.1
[root@VM-8-3-centos local]# npm -v
8.0.0

# 安装完成 删除 下载的 node 压缩包
[root@VM-8-3-centos local]# rm node-v16.11.1-linux-x64.tar
rm: remove regular file ‘node-v16.11.1-linux-x64.tar’? y

[root@VM-8-3-centos local]# ls
bin  etc  games  include  lib  lib64  libexec  nginx  node-v16.11.1-linux-x64  qcloud  sbin  share  soft  src  yd.socket.server


参考

linux服务器快速卸载安装node环境(简单上手)
linux xz压缩解压
Linux tar 命令

posted @ 2021-10-16 09:23  暗恋桃埖源  阅读(1006)  评论(0编辑  收藏  举报