1

I am trying to update nodejs version using npm.

Install nodejs:

sudo yum install nodejs npm --enablerepo=epel

Check Version

[root@*********** ec2-user]# node -v
v0.10.46
[root@*********** ec2-user]# npm -v
1.3.6

Install n and Update 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

Check the Version:

[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

When i do which node and which npm from root user:

[root@ip-********]# which node
/usr/bin/node
[root@************]# which npm
/usr/bin/npm

if i login as ec2-user instead of root its showing recent version correctly :

[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

Can anyone please help me out here to resolve this issue.

nad87563
  • 3,672
  • 7
  • 32
  • 54

1 Answers1

2

It's kinda hack but you can resolve it by creating symlink

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

Tom
  • 81
  • 5
  • hi Tom thanks for your answer.it resolved the issue. do you why its not able to fecth the latest version though? when i do node -v from root user and works perfectly when i do node -v from ec2-user. – nad87563 Aug 25 '16 at 21:19
  • I am not sure why but it seems like you have two different versions of node and npm installed. if you want to run multiple versions of node and npm you can install nvm (https://github.com/creationix/nvm). – Tom Aug 26 '16 at 16:03
  • its odd because i did not install two different version of node and npm. i installed using 'yum install nodejs npm' and then updated by giving 'npm install -g n' and 'n stable' . – nad87563 Aug 26 '16 at 16:08