00 实验环境

  1. # 发行版信息
  2. [root@localhost ~]# cat /etc/redhat-release
  3. CentOS Linux release 7.6.1810 (Core)
  4. # 内核
  5. [root@localhost ~]# uname -r
  6. 3.10.0-957.el7.x86_64

01 实验目的

在本机上通过二进制安装的方式安装node多实例并配置

02 实验软件选择

node 最新版
http://nodejs.cn/download/
https://npm.taobao.org/mirrors/node/v10.15.0/node-v10.15.0-linux-x64.tar.xz

03 安装和配置

030 下载

  1. [root@web01 opt]# cd /root/tools/
  2. [root@web01 tools]# pwd
  3. /root/tools
  4. #下载二进制解压包
  5. [root@web01 tools]# wget https://npm.taobao.org/mirrors/node/v10.15.0/node-v10.15.0-linux-x64.tar.xz
  6. [root@web01 tools]# ls
  7. nginx-1.14.2 node-v10.15.0-linux-x64.tar.xz Python-3.6.8.tgz
  8. nginx-1.14.2.tar.gz Python-3.6.8

031 解压

  1. # 解压tar.gz包
  2. [root@web01 tools]# tar xf node-v10.15.0-linux-x64.tar.xz
  3. [root@web01 tools]# ls
  4. nginx-1.14.2 node-v10.15.0-linux-x64 Python-3.6.8
  5. nginx-1.14.2.tar.gz node-v10.15.0-linux-x64.tar.xz Python-3.6.8.tgz
  6. [root@web01 tools]# cd node-v10.15.0-linux-x64
  7. [root@web01 node-v10.15.0-linux-x64]# ls
  8. bin CHANGELOG.md include lib LICENSE README.md share

032 拷贝文件到简单的文件目录

  1. [root@web01 node-v10.15.0-linux-x64]# cd ..
  2. [root@web01 tools]# cp node-v10.15.0-linux-x64 /opt/ -r
  3. [root@web01 tools]# cd /opt/
  4. [root@web01 opt]# ls
  5. luffy_boy.tar.gz nginx-1.14.2 node-v10.15.0-linux-x64 vue_project.tar.gz
  6. nginx node-10.15 python3
  7. [root@web01 opt]# cp node-v10.15.0-linux-x64/* node-10.15/ -r
  8. [root@web01 opt]# cd node-10.15/
  9. [root@web01 node-10.15]# ls
  10. bin CHANGELOG.md include lib LICENSE README.md share
  11. [root@web01 node-10.15]# cd ..
  12. [root@web01 opt]# ls
  13. luffy_boy.tar.gz nginx-1.14.2 node-v10.15.0-linux-x64 vue_project.tar.gz
  14. nginx node-10.15 python3
  15. [root@web01 opt]# rm -fr node-v10.15.0-linux-x64
  16. [root@web01 opt]# ll
  17. total 1700
  18. -rw-r--r--. 1 root root 749056 Jan 14 14:10 luffy_boy.tar.gz
  19. lrwxrwxrwx. 1 root root 17 Jan 12 11:14 nginx -> /opt/nginx-1.14.2
  20. drwxr-xr-x. 11 root root 171 Jan 12 11:19 nginx-1.14.2
  21. drwxr-xr-x. 6 root root 108 Jan 14 14:18 node-10.15
  22. drwxr-xr-x. 6 root root 56 Jan 12 15:51 python3
  23. -rw-r--r--. 1 root root 988160 Jan 14 14:10 vue_project.tar.gz

033 创建软连接

# 创建软连接
[root@web01 opt]# ln -s node-10.15 node
[root@web01 opt]# ls
luffy_boy.tar.gz  nginx  nginx-1.14.2  node  node-10.15  python3  vue_project.tar.gz
[root@web01 opt]# ll
total 1700
-rw-r--r--.  1 root root 749056 Jan 14 14:10 luffy_boy.tar.gz
lrwxrwxrwx.  1 root root     17 Jan 12 11:14 nginx -> /opt/nginx-1.14.2
drwxr-xr-x. 11 root root    171 Jan 12 11:19 nginx-1.14.2
lrwxrwxrwx.  1 root root     10 Jan 14 14:20 node -> node-10.15
drwxr-xr-x.  6 root root    108 Jan 14 14:18 node-10.15
drwxr-xr-x.  6 root root     56 Jan 12 15:51 python3
-rw-r--r--.  1 root root 988160 Jan 14 14:10 vue_project.tar.gz

034 添加全局变量

# 添加全局path变量
[root@web01 opt]# echo 'PATH=/opt/node/bin:$PATH' >>/etc/profile
[root@web01 opt]# source /etc/profile

04 运行测试

[root@web01 opt]# node -V
node: bad option: -V
[root@web01 opt]# node -v
v10.15.0
[root@web01 opt]# npm -v
6.4.1

005 一键安装

cd /opt &&
wget https://npm.taobao.org/mirrors/node/v10.15.0/node-v10.15.0-linux-x64.tar.xz &&
tar xf node-v10.15.0-linux-x64.tar.xz  &&
mv node-v10.15.0-linux-x64 node-10.15  &&
ln -s node-10.15 node &&
echo 'export PATH=/opt/node/bin:$PATH' >>/etc/profile  &&
source /etc/profile