centos 默认安装
[root@localhost ~]# yum -y install nodejs
[root@localhost ~]# node -v
v6.17.1
[root@localhost ~]# npm -v
3.10.10
#查看npm仓库地址
npm get registry
#更改npm仓库地址
npm config set registry https://registry.npmjs.org/
npm config set registry https://registry.npm.taobao.org
#安装指定版本在@后面添加版本号,并可指定仓库地址
npm install -g npm@5.6.0 --registry=https://registry.npm.taobao.org
# npm -g install npm@5.6.0 --registry=https://registry.npm.taobao.org ###以下为错误信息
- asap@2.0.5 node_modules/npm/node_modules/asap
- fstream@1.0.10 node_modules/npm/node_modules/fstream
- fstream-npm@1.2.0 node_modules/npm/node_modules/fstream-npm
- normalize-git-url@3.0.2 node_modules/npm/node_modules/normalize-git-url
- realize-package-specifier@3.0.3 node_modules/npm/node_modules/realize-package-specifier
/usr/lib
└── (empty)
npm ERR! Linux 3.10.0-862.el7.x86_64
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "-g" "install" "npm@5.6.0" "--registry=https://registry.npm.taobao.org"
npm ERR! node v6.17.1
npm ERR! npm v3.10.10
npm ERR! path /usr/lib/node_modules/npm/node_modules/columnify
npm ERR! code EEXIST
npm ERR! errno -17
npm ERR! syscall mkdir
npm ERR! EEXIST: file already exists, mkdir '/usr/lib/node_modules/npm/node_modules/columnify'
npm ERR! File exists: /usr/lib/node_modules/npm/node_modules/columnify
npm ERR! Move it away, and try again.
npm ERR! Linux 3.10.0-862.el7.x86_64
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "-g" "install" "npm@5.6.0" "--registry=https://registry.npm.taobao.org"
npm ERR! node v6.17.1
npm ERR! npm v3.10.10
npm ERR! path npm-debug.log.3436820402
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open 'npm-debug.log.3436820402'
npm ERR! enoent ENOENT: no such file or directory, open 'npm-debug.log.3436820402'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /usr/lib/node_modules/npm/node_modules.bundled/columnify/npm-debug.log
npm ERR! code 1
###npm命令失效
这时需卸载rpm包后,重新安装
rpm -e npm-3.10.10-1.6.17.1.1.el7.x86_64 --nodeps
rpm -e nodejs-6.17.1-1.el7.x86_64
删除npm缓存和模块
npm cache clean --force
npm install rimraf -g
rimraf node_modules
注:本例为root安装,不存在权限问题,并多次安装均失败
下载高版本node的rpm包安装
nodejs-10.24.1-1nodesource.x86_64.rpm
下载地址:https://download.csdn.net/download/zhangxueleishamo/77848815
yum源curl -sL https://rpm.nodesource.com/setup_10.x | bash -
yum clean all
yum makecache fast
yum -y install nodejs-10.24.1-1nodesource.x86_64.rpm
[root@spug yum.repos.d]# node -v
v10.24.1
[root@spug yum.repos.d]# npm -v
6.14.12