Give
sudo
your current PATH
with:sudo env "PATH=$PATH" your_command
Elaborating on @opyate's answer, I am using the following shell script (which may be named
mysudo
, for example):#!/bin/bash
sudo -E env "PATH=$PATH" "$@"
-E
tellssudo
to preserve the environment.env "PATH=$PATH"
is expanded outside thesudo
call, making the externalPATH
available inside thesudo
too (this is required in addition to the-E
as thePATH
usually receives special treatment in addition to the treatment the entire environment receives)."$@"
passes the arguments our script receives to thesudo
line.
PATH
, give it +x
permissions, et voilĂ .
Since the current answers are a little vague, the specific setting in
/etc/sudoers
changing your path is secure_path
:Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
You can modify it it with sudo visudo
, or better yet, add the directories you need:Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin