Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

My PATH from user shell :

/usr/local/bin:/usr/bin:/bin:/opt/bin

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

/usr/sbin:/usr/bin:/sbin:/bin

My PATH from root shell, via sudo -s :

/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin

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 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 at 9:14

1 Answer 1

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 at 9:13

Your Answer

 
discard

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.