I am connecting with ssh from a Mac to a Ubuntu machine with Homebrew installed (as per these instructions). When using the Ubuntu machine directly, brew works fine. But with ssh, I get the the message zsh: command not found: brew. I am using zsh with oh-my-zsh on both machines. The PATH variable when I connect using ssh is not the same (doesn't have many of the locations, including the one for brew) as when I'm using the machine directly. I suspect the problem may be the one mentioned here, but I couldn't quite figure out what the solution is.

Would be of very useful to know how to get the same path as on the machine when connecting via ssh. Thanks.

1 Answer 1


I have managed to solve this problem with some inspiration from the comments in the answers to this SO question.

Adding export PATH=:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:$PATH to the .zshenv file in the home directory (may have to be created if it does not exist already) solved the problem, and now I see the full path when I ssh in.

My understanding of the cause for the problem is that ssh connects via non-interactive mode (not entirely sure what that is!). The entire PATH variable of the Ubuntu machine is not sourced when accessing remotely via ssh non-interactively. The brew path is appended directly to the PATH env variable once (i.e., is not appended via .zshrc etc during login/connection etc.). .zshrc is sourced even when a non-interactive connection is made, and appending the path there solved the problem. It didn't change the PATH env variable when using the Ubuntu machine directly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .