I'm having trouble with my PATH. I have a clean instance of an Amazon Linux virtual server and I set this in /etc/profile


In my myuser (my own user) account, I set this in my ~/.bash_profile


And then when I output the "env" as my user I get


But when I output it as sudo I get

sudo env

How do I get my sudo user to use the same path as my normal user?


Because when you execute sudo you are promoted to root, a different user with a different environment.

You can maintain the same environment variables with --preserve-env option.

This was lifted straight from the man page for sudo and checked on my Linux box under bash. The following give the same output

env | grep PATH

sudo --preserve-env=PATH env | grep PATH 

Check your man page.

  • I'm not clear on how to solve my problem given what you list here. Entering "su - " does not change the PATH var of sudo. – Dave Nov 3 '17 at 18:28
  • I misread the linked post but just rechecked the sudo man page. – bu5hman Nov 5 '17 at 14:39

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