2
ssh bobby@tony:~$ which tmux                                                                        
/usr/bin/tmux
ssh bobby@tony:~$ sudo which tmux                                                                   
/usr/local/bin/tmux
ssh bobby@tony:~$ echo $PATH                                                                        
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/usr/local/sbin:/usr/local/sbin
ssh bobby@tony:~$ sudo echo $PATH                                                                   
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/usr/local/sbin:/usr/local/sbin

Anyone knows what's going on here? Why does sudo which tmux return /usr/local/bin/tmux instead of /usr/bin/tmux?

PS: I have 2 versions of tmux installed (one in /usr/bin and the other in /usr/local/bin).

1 Answer 1

13

It's because your root user has a different path.

sudo echo $PATH

prints your path. It's your shell that does the variable expansion, before sudo starts (and passes it as a command line argument, expanded).

Try:

sudo sh -c 'echo $PATH'
1
  • 1
    Precisely. It's controlled by the secure_path sudoers option. Commented Feb 26, 2012 at 23:35

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.