Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having a little issue with my PATH when I use sudo :

My PATH from user shell :


My PATH from root shell, via su or root login on TTY :


My PATH from root shell, via sudo -s :


As you can see, when using sudo, the order of /bin, /usr/bin and /usr/local/bin is reversed.

It's quite annoying, mainly when I use Vim. I'm used to having vi a symlink to vim. The configuration of symlinks on my Gentoo system is :

/bin/vi     -> busybox
/usr/bin/vi -> vim

So in most cases, simply typing vi brings up Vim, but if I use sudo vi, I end up with the Busibox vi, due to change in PATH order !

I couldn't find out how sudo builds this new path, is there a way to change it ?

share|improve this question
do you use /bin/vi ? You could maybe symlink it to /usr/bin/vi – exussum Jan 7 '14 at 23:21
@user1281385 This symlick is part of the internal Gentoo system, and might be useful in recovery situations. I don't want to delete it. – Levans Jan 8 '14 at 9:14
up vote 4 down vote accepted

Check the /etc/sudoers file or /etc/sudoers.d directory. You should see something like:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin
share|improve this answer
I didn't have such a line, but adding it with correct order did the trick. – Levans Jan 8 '14 at 9:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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