drshapeless


Emacs Installation Tutorial

Tags: emacs

Create: 2022-06-13, Update: 2022-11-27

There are a lot of ways of installing Emacs onto your computer. This post would discuss about the benefits of different approaches.

Platforms

There are three major operating systems, Windows, macOS and GNU/Linux. Emacs supports all three of them.

I have never tried Emacs on Windows. As far as I know, simple usage on Windows is fine, but when it comes to some integration of package, e.g. magit, due to the difference between a Windows shell and a Unix shell, user may have to make a lot of tweaks to get optimal performance. Therefore, I do not recommend using Windows on your personal computer which you can just install GNU/Linux.

I personally use Emacs on both macOS and GNU/Linux, specifically Artix Linux. The experience between those are quite similar until I use EXWM extensively on my Linux machine.

I will only be talking about installing Emacs on macOS and GNU/Linux.

Download binary

The easiest way to install Emacs is through your package manager.

On Arch-based Linux.

pacman -S emacs

On macOS, via homebrew.

brew install emacs

You can download emacs from this site, nil. Although it is perfectly usable, I do not recommend it. The dependencies of this prebuilt binary may be missing on your computer leading to weird bug when launching Emacs.

Downloading binary is extremely simple. But it comes at a cost where you may not get the features you want.

Compiling from source

I personally always compile Emacs from source regularly, which is known as living on HEAD.

Linux

  1. Clone the source.

    git clone https://git.savannah.gnu.org/git/emacs.git
    

    Sometimes, the gnu source is quite slow, you can try the github mirror.

    git clone https://github.com/emacs-mirror/emacs.git
    
  2. Go the emacs directory and run autogen.

    cd emacs
    ./autogen.sh
    

    At this step, you may encounter some errors about missing dependencies. You can install the required dependencies via package manager. If failed, try google the package name with your os. Often it is because the package has a different name in the package repository.

  3. Configure. Configuring may seem to be an alien thing to many people. But here is where we select what features we want in our own Emacs build.

    We can have a look the supported switches.

    ./configure --help
    

    Most of the time, I would compile with these flags.

    ./configure --with-native-compilation \
                --with-imagemagick \
                --with-x \
                --with-x-toolkit=gtk3 \
                --with-xwidgets \
                --with-xinput2
    

    If you are on version 28 or earlier, omit the last --with-xinput2 flag. This is a feature introduced in the latest HEAD that support pixel perfect scrolling.

  4. Build. This will compile Emacs with all the CPU cores of your computer.

    make -j($nproc)
  5. Install.

    sudo make install
    

macOS

On macOS, I personally prefers the emacs-mac build by Mitsuharu Yamamoto. Since it has very great integration with macOS, e.g. smooth scrolling, force touch to open dictionary at point. The only drawback is that, Mr Yamamoto only updates at stable releases. Therefore, the latest version of emacs-mac is still at 28.1.50.

I used to clone the source from him and compile. But thanks to the hard work of github user railwaycat, we can compile with homebrew easily. emacs mac port

  1. Add a new tap.

    brew tap railwaycat/emacsmacport
    
  2. Configure and build. We would also like to check out the available flags.

    brew info emacs-mac
    

    Here is a list of flags I personally use.

    brew install emacs-mac --with-native-compilation \
         --with-mac-metal \
         --with-xwidgets \
         --with-imagemagick
    

    Emacs will automatically build and install.

  3. Add emacs to application folder. This is a script suggested by homebrew after compilation.

    For ARM-based mac, e.g. M1 MacBook.

    osascript -e 'tell application "Finder" to make alias file to POSIX file "/opt/homebrew/opt/emacs-mac/Emacs.app" at POSIX file "/Applications"'
    

    For Intel-based mac.

    osascript -e 'tell application "Finder" to make alias file to POSIX file "/usr/local/opt/emacs-mac/Emacs.app" at POSIX file "/Applications"'
    

Flags explanation

There are a lot of flags for us to configure. I would explain why I choose these compile flags.