Ubuntu 安装/更新 node和npm
2022-07-01 本文已影响0人
夜空最亮的9星
方法是针对系统中已存在nodejs,由于版本低需要升级可以进行如下操作,依次执行即可完成node升级:
sudo npm install n -g
sudo n stable
root@master-node:~# n stable
installing : node-v16.15.1
mkdir : /usr/local/n/versions/node/16.15.1
fetch : https://nodejs.org/dist/v16.15.1/node-v16.15.1-linux-x64.tar.xz
copying : node/16.15.1
installed : v16.15.1 (with npm 8.11.0)
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
If "node --version" shows the old version then start a new shell, or reset the location hash with:
hash -r (for bash, zsh, ash, dash, and ksh)
rehash (for csh and tcsh)
root@master-node:~# node -v
v8.10.0
root@master-node:~# hash -r bash
root@master-node:~# node -v
v16.15.1
root@master-node:~# npm install -g npm@8.13.2
Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo npm install -g npm