Bug 1148400 - npmjs: different versions used by normal and sudo users
npmjs: different versions used by normal and sudo users
Status: RESOLVED INVALID
Classification: openSUSE
Product: openSUSE Tumbleweed
Classification: openSUSE
Component: Other
Current
Other Other
: P5 - None : Normal (vote)
: ---
Assigned To: Adam Majer
E-mail List
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2019-08-27 16:30 UTC by Yunhe Guo
Modified: 2019-08-29 18:27 UTC (History)
1 user (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yunhe Guo 2019-08-27 16:30:23 UTC
Step to reproduce:

1. Install npmjs: sudo zypper in npmjs (installed at /usr/)
2. Update npm with npm: sudo npm i -g npm (installed at /usr/local/)
3. Run: npm -v
3. Run: sudo npm -v

Expected result:

> npm -v
6.11.1
> sudo npm -v
6.11.1

Actual result:

> npm -v
6.11.1
> sudo npm -v
6.9.0

It seems "sudo npm" always using the older version installed at "/usr/" rather than "/usr/local/". But "/usr/local/" should have a higher priority?
Comment 1 Adam Majer 2019-08-29 08:33:01 UTC
Security policy removes /usr/local from your PATH when you do `sudo`. See sudoers config file. So marking this as invalid.


Also, you should never run npm as root in the first place. If you wish to install global commands, those should be added to your own prefix instead. Even doing things like,

> npm config set prefix ~/.npm
> export PATH=~/.npm/bin:$PATH
> npm install -g npm

Add that PATH export to your ~/.bashrc and you are done.

https://medium.com/@ExplosionPills/dont-use-sudo-with-npm-still-66e609f5f92

Now if you wish to install npm global for all users like that, it's OK, but they can all do that themselves locally if they need.
Comment 2 Adam Majer 2019-08-29 08:36:17 UTC
Finally, it's `zypper install npm10` or `zypper install npm12`. Nothing provides npmjs.

> sudo zypper se --provides npmjs
Loading repository data...
Reading installed packages...
No matching items found.
Comment 3 Yunhe Guo 2019-08-29 18:27:48 UTC
I added this to wiki:
https://en.opensuse.org/Node.js#Change_location_of_global_packages