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" "$@"
-Etellssudoto preserve the environment.env "PATH=$PATH"is expanded outside thesudocall, making the externalPATHavailable inside thesudotoo (this is required in addition to the-Eas thePATHusually receives special treatment in addition to the treatment the entire environment receives)."$@"passes the arguments our script receives to thesudoline.
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