0

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

M3_HOME=/usr/local/maven
JAVA_HOME=/usr/java/latest
PATH="$PATH:$M3_HOME/bin:$JAVA_HOME/bin"

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

PATH=$PATH:$HOME/bin

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

PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/maven/bin:/usr/java/latest/bin:/home/myuser/bin

But when I output it as sudo I get

sudo env
PATH=/sbin:/bin:/usr/sbin:/usr/bin

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

-1

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.