Skip Navigation

Compiling Emacs from Source on MacOS Big Sur

Published: 2021-11-09


Recently I started to compile the Emacs master branch from source for daily use instead of using one of the popular formulas on Homebrew.1 It’s pretty cool to try the latest features like the native compilation and the native emoji before the stable releases. Also it’s quite a satisfying experience to be able to compile Emacs from source. It took me several tries to get it right but I think I documented everything. Here are the steps:

Install dependencies

brew install libxml2 gcc libgccjit

Follow the post-installation instruction from libxml2 to fix the path and environment variables.

If you need to have libxml2 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/libxml2/bin:$PATH"' >> ~/.zshrc

For compilers to find libxml2 you may need to set:
  export LDFLAGS="-L/usr/local/opt/libxml2/lib"
  export CPPFLAGS="-I/usr/local/opt/libxml2/include"

For pkg-config to find libxml2 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/libxml2/lib/pkgconfig"


I configured my Emacs with the following options. I’m not exactly sure what each meant but this combination seems to work on my machine:

./configure --with-cairo --with-imagemagick --with-xwidgets --with-native-compilation
# Build MacOS App bundle, `install` doesn’t actually install anything.
make clean install

The App bundle should now be in the nextstep/ directory. Simply copy it to the /Applications folder to use it.



  1. Probably the popular options are: emacs-mac, emacs-plus, and emacs-head. I was mostly using emacs-mac in the past.↩︎

This work is licensed under a Creative Commons Attribution 4.0 International License.