Node.js

解压 nodejs 包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
root@ox [11:07:30 PM] [~/Downloads] 
-> # ls -la
total 20896
drwxr-xr-x. 2 root root 44 Apr 25 23:06 .
dr-xr-x---. 17 root root 4096 Apr 25 23:07 ..
-rwxrw-rw-. 1 root root 21391564 Apr 25 11:32 node-v14.16.1-linux-x64.tar.xz
root@ox [11:07:46 PM] [~/Downloads]
-> # tar -xvf node-v14.16.1-linux-x64.tar.xz
...
···
root@ox [11:19:26 PM] [~/Downloads]
-> # ll
total 21M
-rwxrw-rw-. 1 root root 21M Apr 25 11:32 node-v14.16.1-linux-x64.tar.xz
drwxr-xr-x. 6 1001 1001 108 Apr 7 01:28 node-v14.16.1-linux-x64

移动 nodejs 文件至 /usr/local

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
27
28
29
30
31
32
root@ox [11:20:53 PM] [~/Downloads] 
-> # cd /usr/local
root@ox [11:21:00 PM] [/usr/local]
-> # mkdir node
root@ox [11:21:04 PM] [/usr/local]
-> # ll
total 0
drwxr-xr-x. 2 root root 6 Apr 11 2018 bin
drwxr-xr-x. 2 root root 6 Apr 11 2018 etc
drwxr-xr-x. 2 root root 6 Apr 11 2018 games
drwxr-xr-x. 2 root root 6 Apr 11 2018 include
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64
drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec
drwxr-xr-x. 2 root root 6 Apr 25 23:21 node
drwxr-xr-x. 2 root root 6 Apr 11 2018 sbin
drwxr-xr-x. 5 root root 49 Apr 25 20:41 share
drwxr-xr-x. 2 root root 6 Apr 11 2018 src
root@ox [11:21:05 PM] [/usr/local]
-> # mv /root/Downloads/node-v14.16.1-linux-x64 /usr/local/node/v14.16.1
root@ox [11:21:52 PM] [/usr/local/node]
-> # cd node/v14.16.1/
root@ox [11:21:55 PM] [/usr/local/node/v14.16.1]
-> # ll
total 168K
drwxr-xr-x. 2 1001 1001 40 Apr 7 01:28 bin
-rw-r--r--. 1 1001 1001 53K Apr 7 01:28 CHANGELOG.md
drwxr-xr-x. 3 1001 1001 18 Apr 7 01:28 include
drwxr-xr-x. 3 1001 1001 26 Apr 7 01:28 lib
-rw-r--r--. 1 1001 1001 79K Apr 7 01:28 LICENSE
-rw-r--r--. 1 1001 1001 29K Apr 7 01:28 README.md
drwxr-xr-x. 5 1001 1001 45 Apr 7 01:28 share

配置 NODE_PATH

1
2
root@ox [11:28:54 PM] [~] 
-> # vim /etc/profile

文件末尾添加以下内容:

1
2
3
# Node
export NODE_HOME=/usr/local/node/v14.16.1
export PATH=$PATH:$NODE_HOME/bin

使 /etc/profile 修改生效:

1
2
root@ox [11:32:28 PM] [~] 
-> # source /etc/profile

查看版本

1
2
3
4
5
6
root@ox [11:32:35 PM] [~] 
-> # node -v
v14.16.1
root@ox [11:32:37 PM] [~]
-> # npm -v
6.14.12

使用腾讯云镜像源加速 npm

1
2
3
4
5
root@ox [11:38:15 PM] [~] 
-> # npm config set registry http://mirrors.cloud.tencent.com/npm/
root@ox [11:41:24 PM] [~]
-> # npm config get registry
http://mirrors.cloud.tencent.com/npm/