I have two versions of emacs on my machine. One came preinstalled and I have just installed a newer version with homebrew.

enter image description here

If I type emacs in the terminal, the old version runs. If I type emacs-24.4 then the new version runs. What do I have to do to ensure typing just emacs runs the 24.4 version and not the older version?

  • What is your PATH? – mmmmmm Feb 25 '15 at 14:13
  • My $PATH is quite long, but it includes /usr/local/Cellar/emacs/24.4/bin/ – Gordonium Feb 25 '15 at 14:16
  • Not the best way I think ;) Homebrew should have links from /usr/local/bin to the cellar and then /usr/local.bin is in your path. However the issue is is is which directory that contains an executable emacs is first in the $PATH – mmmmmm Feb 25 '15 at 14:19

To do this for just Emacs, use

alias emacs=/usr/local/bin/emacs

in your shell startup file which will make Emacs always run Homebrew emacs instead of whatever is first in your $PATH.

But the better way to do this is to make your shell always look for Homebrew versions of commands first, by putting /usr/local/bin first, or at least early, in your $PATH.

So if your $PATH is set like this:

export PATH="$PATH:/usr/local/bin"

change it to this:

export PATH="/usr/local/bin:$PATH"

/usr/local/bin is a directory containing symlinks to all Homebrew-installed commands, Emacs included, and your shell starts at the beginning of the $PATH to figure out what executable to use, so putting it first will in effect choose the Homebrew emacs first.

One last thing - please remove /usr/local/Cellar/emacs/24.4/bin from your $PATH. It's going to break when the next version of Emacs comes out. If you use /usr/local/bin instead, Homebrew will automatically manage the symlinks when you update things.

| improve this answer | |

You must log in to answer this question.

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