下载nodeJs https://nodejs.org/en/download/stable/

1.下载安装包

1
2
3
4
5
6
7
8
9
10
11
[root@localhost]# wget http://nodejs.org/dist/v5.7.1/node-v5.7.1-linux-x64.tar.xz
--2016-03-06 14:17:04-- http://nodejs.org/dist/v5.7.1/node-v5.7.1-linux-x64.tar.xz
Resolving nodejs.org... 104.20.22.46, 104.20.23.46
Connecting to nodejs.org|104.20.22.46|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8374600 (8.0M) [application/x-xz]
Saving to: “node-v5.7.1-linux-x64.tar.xz”
100%[=====================================================================================================================================================>] 8,374,600 41.5K/s in 2m 22s
2016-03-06 14:19:37 (57.7 KB/s) - “node-v5.7.1-linux-x64.tar.xz” saved [8374600/8374600]

###2.解压文件tar.xz

因为是tar.xz结尾的文件,要xz一下,再tar一下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[root@localhost]# xz -d node-v5.7.1-linux-x64.tar.xz
[root@localhost]# tar -xvf node-v5.7.1-linux-x64.tar
ode-v5.7.1-linux-x64/
node-v5.7.1-linux-x64/bin/
node-v5.7.1-linux-x64/bin/npm
node-v5.7.1-linux-x64/bin/node
node-v5.7.1-linux-x64/share/
node-v5.7.1-linux-x64/share/man/
node-v5.7.1-linux-x64/share/man/man1/
node-v5.7.1-linux-x64/share/man/man1/node.1
node-v5.7.1-linux-x64/share/systemtap/
node-v5.7.1-linux-x64/share/systemtap/tapset/
node-v5.7.1-linux-x64/share/systemtap/tapset/node.stp
node-v5.7.1-linux-x64/share/doc/
node-v5.7.1-linux-x64/share/doc/node/
node-v5.7.1-linux-x64/share/doc/node/gdbinit
node-v5.7.1-linux-x64/LICENSE
node-v5.7.1-linux-x64/include/
node-v5.7.1-linux-x64/include/node/
node-v5.7.1-linux-x64/include/node/zconf.h
node-v5.7.1-linux-x64/include/node/uv-sunos.h
[root@localhost]# cd node
[root@localhost node]# cd bin
[root@localhost bin]# ./node -v
v5.7.1

node-v5.7.1-linux-x64命名为node放到指定目录,我是放在/home下面

###3.配置node全局运行

1
[root@localhost] vi /etc/profile

将下面加入文件最后面

1
2
export NODE_HOME=/home/node
export PATH=$NODE_HOME/bin:$PATH

使 /etc/profile 生效

1
source /etc/profile

###4、安装npm

1
2
apt-get install npm
npm install -g npm