
2.2 Linux下部署Node.js开发环境
在Linux下安装Node.js有很多种方法,常见的方法有通过包管理器安装Node.js、源码安装。下面针对各种版本的Linux和安装方法进行介绍。
2.2.1 通过源码安装Node.js
下面以Ubuntu 14.04为例说明如何使用源码安装Node.js。
(1)首先,通过下面的命令安装版本工具。

(2)其次,新建一个目录,并使用wget命令下载Node.js源码。

或者通过git直接从GitHub上复制。

(3)最后配置安装选项并进行编译安装,其中X代表服务器的CPU数量。

安装成功后,可以使用node –v命令来检查Node.js的版本以及是否安装成功。
提示
Node.js选择下载源码进行编译安装之前,要确保系统安装了Python 2.6或2.7。
2.2.2 通过包管理器安装Node.js
在Linux的不同版本下可以使用NPM进行Node.js安装。下面仅列举几种常见的Linux发布版的方法。
1.Arch Linux
在Arch Linux中Node.js和NPM包是全面支持的,可以通过一条指令进行安装:

2.基于Debian和Ubuntu的Linux发布版
基于Debian和Ubuntu的Linux发布版本主要包括Linux Mint、Linux Mint Debian Edition(LMDE)和elementaryOS,可以通过Debian和Ubuntu的社区NodeSource来下载和安装,在GitHub上的链接地址是https://github.com/nodesource/distributions。需要注意的是,通过nodesource安装的版本可能并不是最新的。
● 安装Node.js 4.x版本的方法如下:

● 安装nodejs v6版本的方法如下:

3.Red Hat Enterprise Linux/RHEL、CentOS和Fedora
在Red Hat、CentOS和Fedora上使用NPM安装Node.js的时候需要修改对应的地址,具体版本的链接可能略有不同。要使用root用户登录,并执行下面的命令:
● 4.x版本

● 6.x版本

然后使用yum命令来安装Node.js:

在Fedora 18之后的版本,Node.js和NPM是默认支持的,只需要通过下面的一条命令就可以安装:
