Im using Zsh on the client and server. When I use ssh to run a command on the remote server it can not find the binary:

ssh gt "cd /home/****/app/staging && bundle exec rake db:migrate RAILS_ENV=staging"
zsh:1: command not found: bundle

I can run the same command fine if I SSH in with an interactive shell.

On the server the $PATH is set in both .zshrc and .zshenv


It appears bundle is not in my $PATH on the server. Maybe this has something to do with RVM (Ruby Version Manager) which hooks in to cd, so when you cd in to a directory with a .rvmrc file it sets up the Ruby environment and adds bundle to the $PATH. I need to find out if the cd hook is also triggered for non-interactive shells.

3 Answers 3


The path in which your binary is, is probably added to the $PATH variable on login. And when you run the presented command, it is executed via a non-login shell. The easiest (and safe) way of solving this is to specify a full path in this case.

  • 4
    As I read man zsh, the file sourced by non-login shells is .zshenv. This means that bundle is not found in the $PATH set in that file. Do a simple check ssh gt 'echo $PATH' (mind the single quotes!). Commented Nov 4, 2011 at 10:59
  • It looks like single quotes may have been the issue, changing from double quotes to single seems to have fixed the issue.
    – Kris
    Commented Nov 4, 2011 at 13:48

I upvoted the comment by @rozcietrewiacz, but I want to call it out as a full answer. (This wouldn't have helped the poster who had already set both dotfiles, but I think it will help people like me who find this question based on the error.)

zsh reads .zshenv and .zshrc for interactive logins, but only .zshenv for noninteractive logins. To fix this problem, I needed to split out the PATH settings from my .zshrc and move them to .zshenv.

In my case, I was unable to run mercurial commands that communicated by ssh with another server, because my path (with hg itself) was set in .zshrc on the server.

More detail can be found here and here.


the reason is the PATH here.

please do a which bundle , on both the shells, that should be self-explanatory ! and you could either edit the PATH variable exporting it to your needs, or use absolute paths for the same.

You must log in to answer this question.

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