我正在尝试使用npm更新nodejs版本。
安装nodejs:
sudo yum install nodejs npm --enablerepo=epel
检查版本
[root@*********** ec2-user]# node -v
v0.10.46
[root@*********** ec2-user]# npm -v
1.3.6
安装n和更新nodejs:
[root@ip************#] sudo npm install -g n
npm http GET https://registry.npmjs.org/n
npm http 200 https://registry.npmjs.org/n
npm http GET https://registry.npmjs.org/n/-/n-2.1.4.tgz
npm http 200 https://registry.npmjs.org/n/-/n-2.1.4.tgz
/usr/bin/n -> /usr/lib/node_modules/n/bin/n
npm WARN unmet dependency /usr/lib/node_modules/block-stream requires inherits@'~2.0.0' but will load
npm WARN unmet dependency undefined,
npm WARN unmet dependency which is version undefined
npm WARN unmet dependency /usr/lib/node_modules/fstream requires inherits@'~2.0.0' but will load
npm WARN unmet dependency undefined,
npm WARN unmet dependency which is version undefined
npm WARN unmet dependency /usr/lib/node_modules/fstream-ignore requires inherits@'2' but will load
npm WARN unmet dependency undefined,
npm WARN unmet dependency which is version undefined
npm WARN unmet dependency /usr/lib/node_modules/fstream-npm requires inherits@'2' but will load
npm WARN unmet dependency undefined,
npm WARN unmet dependency which is version undefined
npm WARN unmet dependency /usr/lib/node_modules/glob requires inherits@'2' but will load
npm WARN unmet dependency undefined,
npm WARN unmet dependency which is version undefined
npm WARN unmet dependency /usr/lib/node_modules/npmconf requires inherits@'~2.0.0' but will load
npm WARN unmet dependency undefined,
npm WARN unmet dependency which is version undefined
npm WARN unmet dependency /usr/lib/node_modules/tar requires inherits@'2' but will load
npm WARN unmet dependency undefined,
npm WARN unmet dependency which is version undefined
n@2.1.4 /usr/lib/node_modules/n
[root@i*************# n stable
install : node-v6.4.0
mkdir : /usr/local/n/versions/node/6.4.0
fetch : https://nodejs.org/dist/v6.4.0/node-v6.4.0-linux-x64.tar.gz
######################################################################## 100.0%
installed : v0.10.46
检查版本:
[root@*********** ec2-user]# node -v
v0.10.46
[root@*********** ec2-user]# npm -v
1.3.6
[root@*********** ec2-user]#/usr/local/bin/node -v
v6.4.0
[root@*********** ec2-user]# /usr/local/bin/npm -v
3.10.3
当我执行哪个节点以及root用户的npm时:
[root@ip-********]# which node
/usr/bin/node
[root@************]# which npm
/usr/bin/npm
如果我以ec2-user而不是root身份登录,则会正确显示最新版本:
[ec2-user@ip************** ~]$ node -v
v6.4.0
[ec2-user@ip************** ~]$ npm -v
3.10.3
[ec2-user@ip************** ~]$ which node
/usr/local/bin/node
[ec2-user@ip************** ~]$ which npm
/usr/local/bin/npm
有谁可以帮我解决这个问题。
答案 0 :(得分:1)
有点黑客,但您可以通过创建符号链接来解决它
mv /usr/bin/node /usr/bin/bnode
ln -s /usr/local/bin/node /usr/bin/node
mv /usr/bin/npm /usr/bin/bnpm
ln -s /usr/local/bin/npm /usr/bin/npm