📅 2015-Jul-31 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ environment variables, sudo ⬩ 📚 Archive
Using sudo
is a common, safe and recommended method to execute commands that require superuser privileges. However, this command resets the PATH
environment variable. So, some badly written installation scripts that require a particular PATH
will fail in strange ways when run as sudo
.
Here is some useful information about sudo
and the PATH
environment variable:
To ensure safety, sudo
by default does not use the PATH
environment variable of the user or that of root
.
sudo
also ignores the system-wide environment variables set in /etc/environment
or in /etc/profile.d/*.sh
.
The PATH
variable for sudo
is hardcoded to /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
If you really want sudo
to pick up the system-wide PATH
or other environment variables, then try this:
PATH
or environment variable in a new file named /etc/profile.d/name_anything.sh
using export
sudo su -
echo $PATH
sudoers
man page, look for env_reset
Tried with: Ubuntu 14.04