1.下载nodejs,如centos上面网络不太好,可以在本地浏览器下载好之后上传到服务器
wget https://nodejs.org/dist/v11.10.0/node-v11.10.0-linux-x64.tar.xz
tar xvJf node-v11.10.0-linux-x64.tar.xz
2.进到bin目录查看版本,发现npm命令不可以用,需要重新安装过才行
cd /work/node-v11.10.0-linux-x64/bin
/work/node-v11.10.0-linux-x64/lib/node_modules/npm/bin/npm-cli.js:85
let notifier = require('update-notifier')({pkg})
^^^^^^^^
SyntaxError: Unexpected identifier
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:945:3
3.设置环境变量
sudo vi /etc/profile
文件末尾加入
export NODE_HOME=/work/node-v11.10.0-linux-x64
export PATH=$NODE_HOME/bin:$PATH
export NODE_PATH=$NODE_HOME/lib/node_modules
完成编辑后,执行source /etc/profile
4.查看环境变量是否生效
5.下载npm的rpm包,该包可能不是最好匹配
http://www.rpmfind.net/linux/rpm2html/search.php?query=npm&submit=Search+...&system=centos&arch=
6.安装,可能报错
[appadmin@disrtsvr02 work]$ sudo yum -y localinstall npm-6.9.0-1.10.16.3.2.module_el8.0.0+186+
542b25fc.x86_64.rpm Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Local Package Process
Examining npm-6.9.0-1.10.16.3.2.module_el8.0.0+186+542b25fc.x86_64.rpm: 1:npm-6.9.0-1.10.16.3.
2.module_el8.0.0+186+542b25fc.x86_64Marking npm-6.9.0-1.10.16.3.2.module_el8.0.0+186+542b25fc.x86_64.rpm to be installed
Loading mirror speeds from cached hostfile
Could not get metalink https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=x86_64 erro
r was14: problem making ssl connection
* epel: mirrors.tuna.tsinghua.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package npm.x86_64 1:6.9.0-1.10.16.3.2.module_el8.0.0+186+542b25fc will be installed
--> Processing Dependency: nodejs = 1:10.16.3-2.module_el8.0.0+186+542b25fc for package: 1:npm
-6.9.0-1.10.16.3.2.module_el8.0.0+186+542b25fc.x86_64--> Processing Dependency: /usr/bin/sh for package: 1:npm-6.9.0-1.10.16.3.2.module_el8.0.0+186
+542b25fc.x86_64--> Processing Dependency: /usr/bin/sh for package: 1:npm-6.9.0-1.10.16.3.2.module_el8.0.0+186
+542b25fc.x86_64--> Finished Dependency Resolution
Error: Package: 1:npm-6.9.0-1.10.16.3.2.module_el8.0.0+186+542b25fc.x86_64 (/npm-6.9.0-1.10.16
.3.2.module_el8.0.0+186+542b25fc.x86_64) Requires: /usr/bin/sh
Error: Package: 1:npm-6.9.0-1.10.16.3.2.module_el8.0.0+186+542b25fc.x86_64 (/npm-6.9.0-1.10.16
.3.2.module_el8.0.0+186+542b25fc.x86_64) Requires: nodejs = 1:10.16.3-2.module_el8.0.0+186+542b25fc
Installed: nodejs-0.10.48-3.el6.x86_64 (@epel)
nodejs = 0.10.48-3.el6
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
改为另一种方式执行(只是忽略报错,没有根本上解决错误)
sudo yum -y localinstall npm-6.9.0-1.10.16.3.2.module_el8.0.0+186+
542b25fc.x86_64.rpm --skip-broken
7.安装cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
8.安装elasticdump
cnpm install elasticdump -g