Installing emacs 24 or 25 on Mac OS X Sierra

Mac OS X Sierra 10.12.5 already has an old version of emacs installed to /usr/bin/emacs and it can’t be removed.

You used to be able to rename the files from emacs to emacs22, so that when you install another version they wouldn’t conflict. Good in theory, but in El Captain and newer, Apple have changes the security on the file system

This used to work:

sudo mv /usr/bin/emacs/emacs22  
sudo mv /usr/bin/emacsclient emacsclient22  
sudo mv /usr/bin/emacs-undumped emacs22-undumped

But this no longer works because of a new “System Integrity System” that makes Mac OS X “rootless” more details here.

So, instead I’m going to install macports.

Firstly, Install MacPorts for Mac OS X Sierra 10.12.5 and install the downloaded package by double clicking on the downloaded MacPorts-2.4.1-10.12-Sierra.pkg package.

MacPorts required the xcode command line tools. Install this next:

xcode-select --install  
sudo port install emacs  

This solves my problem because the /opt/local/bin/ path is searched before the /usr/bin/ path, so anything in the opt path will take precedence over /usr/bin and I don’t need to uninstall emacs 22.

Now let’s see which emacs is run:

osx:~$ which emacs  
/opt/local/bin/emacs

osx:~$ emacs --version  
GNU Emacs 25.2.1

Perfect.