1. 删除PPA源
这一步仅在安装了Node.js PPA.
# add-apt-repository may not be present on some Ubuntu releases:
# sudo apt-get install python-software-properties
sudo add-apt-repository -y -r ppa:chris-lea/node.js
sudo rm -f /etc/apt/sources.list.d/chris-lea-node_js-*.list
sudo rm -f /etc/apt/sources.list.d/chris-lea-node_js-*.list.save
2. 添加 NodeSource package signing key
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
# wget can also be used:
# wget --quiet -O - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
The key ID is 1655A0AB68576280
.
3. 添加要使用的 NodeSource 软件源
# 修改希望安装的 Node.js 或者 io.js 的版本: node_6.x, node_8.x, etc...
VERSION=node_8.x
DISTRO="$(lsb_release -s -c)"
sudo echo "deb https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo echo "deb-src https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee -a /etc/apt/sources.list.d/nodesource.list
4.更新系统软件包列表安装 Node.js
sudo apt-get update
sudo apt-get install nodejs