一、添加Node.js PPA
首先,您需要在我们的系统中由Nodejs官方网站提供node.js PPA。如果尚未安装,我们还需要安装python-software-properties软件包。您可以选择安装最新的Node.js版本或LTS版本。
最新版安装命令:
curl -sL https://deb.nodesource.com/setup_9.x | sudo bash -
安装LTS长期维护版:
apt-get install curl python-software-properties
curl -sL https://deb.nodesource.com/setup_8.x | bash -
二、安装Node.js和NPM
添加所需的PPA文件后,可以安装Nodejs包。NPM也将与node.js一起安装。该命令还会在您的系统上安装许多其他相关软件包。
apt-get install nodejs
三、检查Node.js和NPM版本
安装node.js后,验证并检查安装的版本。你可以在node.js 官方网站上找到关于当前版本的更多细节。
检查Node.js版本
node -v
检查npm版本
npm -v
根据我们的安装经验,推荐安装 4.x(LTS)版本的 Node.js。
安装 Node.js v4.x
Ubuntu 系统
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
Debian 系统。以 root 权限执行下列指令
curl -sL https://deb.nodesource.com/setup_4.x | bash -
apt-get install -y nodejs
安装 Node.js v0.10
Ubuntu 系统
curl -sL https://deb.nodesource.com/setup_0.10 | sudo -E bash -
sudo apt-get install -y nodejs
Debian 系统。以 root 权限执行下列指令
curl -sL https://deb.nodesource.com/setup_0.10 | bash -
apt-get install -y nodejs
安装 Node.js v0.12
Ubuntu 系统
curl -sL https://deb.nodesource.com/setup_0.12 | sudo -E bash -
sudo apt-get install -y nodejs
Debian 系统。以 root 权限执行下列指令
curl -sL https://deb.nodesource.com/setup_0.12 | bash -
apt-get install -y nodejs
安装 Node.js v5.x
注意:v5.x 的 Node.js 不被 Ghost 支持,以下安装介绍只为了完整介绍 Node.js 各个版本的安装!
Ubuntu 系统
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejs
Debian 系统。以 root 权限执行下列指令
curl -sL https://deb.nodesource.com/setup_5.x | bash -
apt-get install -y nodejs