unbuntu 手动安装npm最新版

下载最新node包

指定版本:16.18.1

sudo wget https://nodejs.org/dist/v16.18.1/node-v16.18.1-linux-x64.tar.xz

新建目录

sudo mkdir -p /usr/local/lib/nodejs
解压缩

sudo tar -xJvf node-v16.18.1-linux-x64.tar.xz -C /usr/local/lib/nodejs

https://nodejs.org/download/release/v12.16.3/node-v12.16.3-linux-x64.tar.xz

v12.16.3

Nodejs

更新环境变量

export PATH=/usr/local/lib/nodejs/node-v16.18.1-linux-x64/bin:$PATH

. ~/.profile

做个链接

sudo ln -sf /usr/local/lib/nodejs/node-v16.18.1-linux-x64/bin/npm /usr/local/bin/
sudo ln -sf /usr/local/lib/nodejs/node-v16.18.1-linux-x64/bin/node /usr/local/bin/

sudo wget https://nodejs.org/dist/v18.12.1/node-v18.12.1-linux-x64.tar.xz

新建目录

sudo mkdir -p /usr/local/lib/nodejs
解压缩

sudo tar -xJvf node-v18.12.1-linux-x64.tar.xz -C /usr/local/lib/nodejs

Nodejs

更新环境变量

export PATH=/usr/local/lib/nodejs/node-v18.12.1-linux-x64/bin:$PATH

. ~/.profile

做个链接

sudo ln -sf /usr/local/lib/nodejs/node-v18.12.1-linux-x64/bin/npm /usr/local/bin/
sudo ln -sf /usr/local/lib/nodejs/node-v18.12.1-linux-x64/bin/node /usr/local/bin/

删除nodejs

  1. sudo apt-get remove –purge npm
  2. sudo apt-get remove –purge nodejs
  3. sudo apt-get remove –purge nodejs-legacy
  4. sudo apt-get autoremove
  5. #手动删除 npm 相关目录
  6. sudo rm -r /usr/local/bin/npm
  7. sudo rm -r /usr/local/lib/node-moudels
  8. sudo find / -name npm
  9. sudo rm -r /tmp/npm*
sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}

自动安装

sudo apt install curl && sudo apt install make

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash –

sudo apt install -y nodejs

标签

发表评论