Sudo user not using same node version

2020-06-16 01:50发布

问题:

I have a strange issue on my server, when ever i try to install packages with npm that require sudo I run into issues and i have discovered that my su and regular user use different node versions.

$ node -v i get node version  0.10.x

But when i do:

$ sudo node -v i get node version 0.6.x

My su user for some reason is using a different node version than what i normally use and this causes compatibility issues when I npm install packages that require sudo.

I have tried sudo apt-get upgrade nodejs at no luck. how do i make su user use same node version as my regular user.

回答1:

run ll /usr/bin/node if this file exist, simply run rm /usr/local/bin/node from the regular user

explanation

If you'd run which node from regular user you will probably see it points to the user local bin directory

which node
/usr/local/bin/node

this means that the regular user installed another node version locally.

to let the same node version apply to all users, this command should show you usr bin (not local).

which node 
/usr/bin/node

by deleting the link from /usr/local/bin/node it will automatically start using /usr/bin/node



回答2:

Try running sudo with the environment of the user:

sudo -E node -v


标签: linux node.js