安装版本:node-v10.15.3
一、安装必要的编译软件包
# yum install gcc gcc-c++ -y
二、从源码下载Nodejs
进入官网选择自己需要的版本
https://nodejs.org/en/download/releases/
# wget https://nodejs.org/download/release/v10.15.3/node-v10.15.3-linux-x64.tar.gz
[root@localhost ~]# wget https://nodejs.org/download/release/v10.15.3/node-v10.15.3-linux-x64.tar.gz --2019-08-02 16:37:28-- https://nodejs.org/download/release/v10.15.3/node-v10.15.3-linux-x64.tar.gz Resolving nodejs.org (nodejs.org)... 104.20.22.46, 104.20.23.46, 2606:4700:10::6814:172e, ... Connecting to nodejs.org (nodejs.org)|104.20.22.46|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 18638507 (18M) [application/gzip] Saving to: ‘node-v10.15.3-linux-x64.tar.gz’ 100%[============================================================================================================================================================================>] 18,638,507 71.7KB/s in 76s 2019-08-02 16:38:47 (240 KB/s) - ‘node-v10.15.3-linux-x64.tar.gz’ saved [18638507/18638507]
查看下载
[root@localhost ~]# ls anaconda-ks.cfg node-v10.15.3-linux-x64.tar.gz [root@localhost ~]# [root@localhost ~]# du -sh node-v10.15.3-linux-x64.tar.gz 18M node-v10.15.3-linux-x64.tar.gz
三、解压 nodejs 安装包
# tar zxvf node-v10.15.3-linux-x64.tar.gz
[root@localhost ~]# ls anaconda-ks.cfg node-v10.15.3-linux-x64 node-v10.15.3-linux-x64.tar.gz
[root@localhost ~]# mv node-v10.15.3-linux-x64 /usr/local
四、进入解压的 node 文件夹,建立软连接
查看bin文件
[root@localhost ~]# cd /usr/local/ [root@localhost local]# [root@localhost local]# ls apache-maven-3.6.1 bin etc games include lib lib64 libexec node-v10.15.3-linux-x64 sbin share src VMOptimizationTools VMOptimizationTools_2.24.0 VMOptimizationToolsLinuxTemp [root@localhost local]# [root@localhost local]# [root@localhost local]# cd node-v10.15.3-linux-x64/ [root@localhost node-v10.15.3-linux-x64]# [root@localhost node-v10.15.3-linux-x64]# ls bin CHANGELOG.md include lib LICENSE README.md share [root@localhost node-v10.15.3-linux-x64]# [root@localhost node-v10.15.3-linux-x64]# cd bin/ [root@localhost bin]# [root@localhost bin]# ls node npm npx [root@localhost bin]#
建立软连接到/usr/bin/
# ln -s /usr/local/node-v10.15.3-linux-x64/bin/node /usr/bin/node
# ln -s /usr/local/node-v10.15.3-linux-x64/bin/npm /usr/bin/npm
[root@localhost bin]# ln -s /usr/local/node-v10.15.3-linux-x64/bin/node /usr/bin/node [root@localhost bin]# [root@localhost bin]# ln -s /usr/local/node-v10.15.3-linux-x64/bin/npm /usr/bin/npm
五、测试
# node -v
# npm -v
[root@localhost ~]# node -v v10.15.3 [root@localhost ~]# [root@localhost ~]# npm -v 6.4.1
参考博客: