Bug 1148400 - npmjs: different versions used by normal and sudo users
npmjs: different versions used by normal and sudo users
Classification: openSUSE
Product: openSUSE Tumbleweed
Classification: openSUSE
Component: Other
Other Other
: P5 - None : Normal (vote)
: ---
Assigned To: Adam Majer
E-mail List
Depends on:
  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: ---


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
> sudo npm -v

Actual result:

> npm -v
> sudo npm -v

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.


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: