For a long time I’ve been using the Emacs For Mac OS X distribution, and it works really well for me.

However, there is a well known issue about the PATH not being the same in Emacs as in the MacOS shell (ie Terminal). For me, this was causing problems when using rspec-mode, because the rspec executable was not on the PATH.

There are several Stack Exchange articles about using the exec-path-from-shell package. This works well, but only if your SHELL variable is correct inside Emacs, and mine was not.

I’m using /bin/zsh instead of the MacOS default /bin/bash, and for some reason Emacs didn’t know that. I could tell by evaluating (getenv "SHELL"), getting "/bin/bash".

I tried googling for solutions to fixing the SHELL but was unable to find a good method. So I ended up going for simplicity and just setting it directly with setenv.

So here is the part of my configuration that fixes SHELL/PATH issue:

(add-to-list 'my-packages 'exec-path-from-shell)
(when (memq window-system '(mac ns))
  (setenv "SHELL" "/bin/zsh")
  (exec-path-from-shell-initialize)
  (exec-path-from-shell-copy-envs
   '("PATH")))

This snippet completely fixes my problems. I can verify in an eshell that my environment is set up properly:

~ $ echo $SHELL
/bin/zsh
~ $ echo $PATH
(my proper PATH as in a shell, notably including ~/.rbenv/shims
which I needed for rspec)