I am on MacOS (darwin) and when I attempt helm-do-grep-ag I get a zsh error zsh:1: command not found: ag. What is the proper way to address this?

My ag is homebrewed and so is in /usr/local/bin

I verified the setting of PATH in both bash and zsh startup, and if I open a shell inside emacs I see /usr/local/bin there. (pasted from emacs shell session:)

echo $PATH

I then also tried adding it to the exec-path variable:

Its value is
("/usr/local/bin" "/usr/bin" "/bin" "/usr/sbin" "/sbin" "/Applications/Emacs.app/Contents/MacOS/libexec" "/Applications/Emacs.app/Contents/MacOS/bin")

I note that variable is defined in 'C source code' and so I suspect it does not influence commands executed from 'helm-grep.el'

As a workaround I customize the variable helm-grep-ag-command to include the explicit full path

Its value is
"/usr/local/bin/ag --line-numbers -S --color --nogroup %s %s %s"
Original value was 
"ag --line-numbers -S --color --nogroup %s %s %s"

But I suspect that is not the proper way to do it. Is this in fact the best way to address that? Or is there a more proper way?

  • 1
    Looks like you need exec-path-from-shell
    – Evan Davis
    Commented Oct 13, 2021 at 18:20
  • @Mathletics exec-path-from-shell appears to have worked. I'm a little disappointed that one needs to install a package to get emacs to work "properly" on a mac, but maybe that's the way it is. I don't know if it's the best solution, but I like it much better than my workaround. I cannot credit you (other than comment +1) because you have only commented and not answered. Commented Oct 13, 2021 at 20:52
  • I think my original confusion was compounded by the fact that running echo $PATH from an emacs shell (i.e. in a buffer obtained from running emacs shell command) may yield different results than (getenv "PATH") especially on a Mac. Commented Oct 13, 2021 at 21:03
  • Added as an answer! I originally didn't answer because I assumed this would get closed as a dupe, but searching around I don't actually see a good replacement.
    – Evan Davis
    Commented Oct 14, 2021 at 15:24

1 Answer 1


This looks like a standard case for exec-path-from-shell.

Essentially, the emacs environment is dependent on where it was started from (e.g. GUI app vs terminal vs daemon, etc.) This package loads your real shell and copies the values into emacs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.