I set PATH in /etc/profile. I do not have any problems in the case of the general user, but PATH does not go when I become the root authority in sudo.

What would you do to override the PATH which is set by /etc/profile even if I become the root authority in sudo?


Sudo resets PATH, along with many other environment variables, for security reasons. It doesn't matter what is set in /etc/profile, unless you run sudo -i.

The sudo manual page, under SECURITY NOTES, gives an insight about the security implications, along with the options you have to fiddle in your /etc/sudoers file to modify these restrictions, after you understand the implications of doing so.


root's path is not changed by /etc/profile (security ...)

you have to set it up separately, (e.g. in root's ~/.bash_profile)



If you want to add a specific PATH to the default PATH of your "root" account when using sudo, or sudo -i:

With Ubuntu 10.04.x LTS:

Modify accordingly both the /etc/environment and the etc/login.defs files.

With Ubuntu 12.04.x LTS:

Modify accordingly both the /etc/environment and the /etc/login.defs files as well as the line Defaults secure_path of the /etc/sudoers file (using visudo).

If you're using a GUI and aren't comfortable with the nano editor in text mode, use the following command to edit the /etc/sudoers file with gedit:

sudo EDITOR=gedit visudo

When you'll save the /etc/sudoers file, visudo will check the syntax of your modifications.

If all is OK, you'll go back to the terminal session.

If there is an error, press the letter "e" to edit the /etc/sudoers file again and correct your modification.

I didn't try with Ubuntu 12.10 yet but I guess (and hope) it's the same thing than for Ubuntu 12.04.x!



In case if your Linux distributions has security policy plugin enabled, the PATH can be overridden by secure_path in your sudoers file, so you need to edit it by sudo visudo and add it to the list.

You can check that if that's the case by:

$ sudo sudo -V | grep PATH
Value to override user's $PATH with: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Alternatively for one-time use, try:

sudo "PATH=$PATH" foo

See: Why are PATH variables different when running via sudo and su? at Unix SE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.