Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.
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

1 Answer 1

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.