Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm doesn't work with sudo #44

Open
skarmoutsosv opened this issue Oct 7, 2022 · 5 comments
Open

npm doesn't work with sudo #44

skarmoutsosv opened this issue Oct 7, 2022 · 5 comments

Comments

@skarmoutsosv
Copy link

$ npm -v
8.19.2

$ node -v
v18.10.0

$ which npm
/snap/bin/npm

$ which node
/snap/bin/node

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin

$ npm install nodemon
up to date, audited 33 packages in 762ms
3 packages are looking for funding
run npm fund for details
found 0 vulnerabilities

$ sudo npm install -g nodemon
sudo: npm: command not found

@jpayne
Copy link

jpayne commented Jun 16, 2023

I’m having the same issue. Did you ever figure this out?

@skarmoutsosv
Copy link
Author

Unfortunately no.
I had to use sources other than snap to make it work.

@simondeziel
Copy link
Contributor

simondeziel commented Feb 3, 2025

$ sudo npm install -g nodemon
sudo: npm: command not found

Could you try and see if /snap/bin is in the PATH sudo uses? sudo env | grep ^PATH | grep :/snap/bin should give you one line, like that:

$ sudo env | grep ^PATH | grep :/snap/bin
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin

On Ubuntu at least, the default /etc/sudoers file contains this:

Defaults	secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

@skarmoutsosv
Copy link
Author

Although my system is somewhat different than it was at the time reporting this, I am still using Debian and the following might useful about this issue.

$ LC_ALL=C date -u
Sun Feb 16 17:24:38 UTC 2025
$ lsb_release -d
No LSB modules are available.
Description:	Debian GNU/Linux 12 (bookworm)
$ uname -srvmo
Linux 6.1.0-31-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.128-1 (2025-02-07) x86_64 GNU/Linux
$ LC_ALL=C apt list snapd
Listing... Done
snapd/stable,now 2.57.6-1+b5 amd64 [installed]
$ LC_ALL=C sudo npm install -g nodemon
sudo: npm: command not found
$ sudo env |grep ^PATH |grep :/snap/bin
$ sudo cat /etc/sudoers | grep secure_path
Defaults	secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

@simondeziel
Copy link
Contributor

@skarmoutsosv your last code block confirms that indeed, your secure_path is missing /snap/bin which is why it's not finding the npm binary that lives under that dir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants