Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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
ssh bobby@tony:~$ which tmux                                                                        
ssh bobby@tony:~$ sudo which tmux                                                                   
ssh bobby@tony:~$ echo $PATH                                                                        
ssh bobby@tony:~$ sudo echo $PATH                                                                   

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).

share|improve this question
up vote 12 down vote accepted

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).


sudo sh -c 'echo $PATH'
share|improve this answer
Precisely. It's controlled by the secure_path sudoers option. – James Youngman Feb 26 '12 at 23:35

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.