How can I set $PATH so I can sudo brew commands?

I removed mc and htop as rpm-ostree layers and installed them for brew. If I sudo them I get command not found unless I include the full path. https://discord.com/channels/1072614816579063828/1087140957096517672/1358084893824909554 If I change to the root user with sudo -i, it is in the path and I can run it just fine.
root@fedora:~# echo $PATH
/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/lib/snapd/snap/bin:/var/home/linuxbrew/.linuxbrew/bin/
root@fedora:~# echo $PATH
/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/lib/snapd/snap/bin:/var/home/linuxbrew/.linuxbrew/bin/
:dispair:
Solution:
GitHub
Running brew-installed utilities with sudo · Homebrew · Discussio...
What's a reasonable way to use sudo together with utilities, installed via brew? I've installed and successfully using command-line utilities via brew on Kubuntu 22.04.1 Sometimes, I need t...
Jump to solution
3 Replies
Solution
asen23
asen233w ago
GitHub
Running brew-installed utilities with sudo · Homebrew · Discussio...
What's a reasonable way to use sudo together with utilities, installed via brew? I've installed and successfully using command-line utilities via brew on Kubuntu 22.04.1 Sometimes, I need t...
biebel
biebelOP3w ago
Thanks! Appending the secure_path in the sudoers file with visudo did it.
biebel
biebelOP3w ago
Super User
How to set path for sudo commands
If I issue sudo my-command how does Linux look for that my-command? The my-command is in my PATH. I can invoke it without any problem. However, when I invoke it with sudo, I'll get command not fou...

Did you find this page helpful?