How to Install Emacs on Mac: A Step-by-Step Guide

Discover step-by-step instructions to install Emacs on Mac using command-line tools and native GUI versions for an optimal setup.

Share
MacBook displaying Emacs on Mac with terminal for how to install Emacs on Mac

You want to try Emacs on your Mac but aren't sure where to start. Whether you're new to Emacs or moving from another editor, macOS presents some unique challenges and opportunities for installation and use. This guide covers how to install Emacs on Mac using both command-line tools and a native Mac GUI version, helping you choose the best approach for your needs.

You'll learn step-by-step instructions for installing via Homebrew, setting up the Emacs Mac Port for a seamless Mac experience, and integrating Emacs with the Mac terminal. Additionally, common issues specific to Mac users are addressed to help you avoid pitfalls and get Emacs running smoothly.

Key takeaways

  • Homebrew provides a straightforward command-line installation of Emacs on Mac.
  • The Emacs Mac Port offers a native GUI version tailored to macOS features.
  • Launching Emacs from the terminal requires proper PATH configuration.
  • Creating and opening files in Emacs follows consistent command shortcuts.
  • Common installation issues often involve permissions or PATH environment misconfigurations.

Before you start: What you need to install Emacs on Mac

Emacs is a powerful and extensible text editor widely used for programming, writing, and managing tasks. On Mac, you can choose between different Emacs versions depending on your preferences for features and integration.

To install Emacs smoothly, ensure your Mac runs a relatively recent version of macOS, typically macOS 10.14 (Mojave) or later for best compatibility. Emacs relies on certain system tools, so having the Xcode Command Line Tools installed is essential. These provide compilers and utilities required during installation.

Another key tool is Homebrew, a popular package manager for macOS that simplifies installing software like Emacs and its dependencies. Installing Homebrew before proceeding will save time and reduce complexity.

Two primary Emacs versions are commonly used on Mac:

VersionKey FeaturesMac IntegrationInstallation Method
GNU EmacsClassic Emacs with wide plugin availabilityTerminal and GUI via Cocoa build; standard experienceHomebrew or manual build
Emacs Mac PortNative Mac interface, better Retina support, improved keybindingsSeamless macOS look and feel, better GUI integrationHomebrew cask or direct download

Before installing, confirm you have:

  1. macOS version 10.14 or newer — Check in System Preferences > About This Mac
  2. Xcode Command Line Tools installed — Run xcode-select --install in Terminal; a successful install shows a confirmation prompt or message
  3. Homebrew installed — Run brew --version in Terminal; you should see the Homebrew version if installed

With these prerequisites, you'll be set for either the classic GNU Emacs or the Emacs Mac Port installation methods covered next.

How to install Emacs on Mac using Homebrew

Homebrew is a popular package manager for macOS that simplifies installing and updating software like Emacs. If you do not have Homebrew installed, you can add it easily via the Terminal.

  1. Open the Terminal app. You can find it in Applications > Utilities or search with Spotlight.
  2. Check if Homebrew is installed by typing brew --version and pressing Enter. If Homebrew is installed, you will see its version number.
  3. If Homebrew is not installed, enter the following command to install it:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    After installation, you should see messages confirming Homebrew was installed successfully.
  4. Once Homebrew is ready, install Emacs by running:
    brew install emacs
  5. Wait for the installation to complete. Terminal output will show the download and compilation progress, ending with a success message.
  6. Verify the installation by typing:
    emacs --version
    You should see the installed Emacs version number displayed.
  7. Launch Emacs from the Terminal by typing emacs and pressing Enter. This opens Emacs in the Terminal window.

Using Homebrew makes managing Emacs updates straightforward. You can update Emacs and other packages by running brew update followed by brew upgrade emacs.

How to install the Emacs Mac Port for a native Mac experience

The Emacs Mac Port delivers a version of Emacs optimized for macOS, offering smoother GUI integration than the standard GNU Emacs build. It supports native macOS features such as better font rendering, fullscreen mode, and native title bars, enhancing your editing experience on Mac.

How to install the Emacs Mac Port for a native Mac experience – how to install Emacs on Mac

To install the Emacs Mac Port, you can use Homebrew Cask or download the pre-built application directly.

  1. Open Terminal and run brew install --cask emacs. This installs the latest stable Emacs Mac Port application in your /Applications folder. When complete, you should see "==> Success!" indicating the app is installed.
  2. Alternatively, visit the official Emacs Mac Port GitHub releases page and download the latest .dmg file. Open the file and drag the Emacs.app into your Applications folder. This method ensures you get the most recent build if Homebrew is outdated.
  3. Once installed, open the Emacs app from your Applications folder. The GUI window should launch with native Mac menus and support for standard macOS keyboard shortcuts like Command-W to close a window.
  4. To launch Emacs Mac Port from Terminal, add the following alias to your shell profile: alias emacs="/Applications/Emacs.app/Contents/MacOS/Emacs". Then run emacs to start the GUI from the command line.
  5. Configure macOS integration by editing your .emacs or init.el file. Enable fullscreen with (setq ns-use-native-fullscreen t) and improve font rendering by setting (set-face-attribute 'default nil:font "Menlo-14") or your preferred font.

The Emacs Mac Port interface features a native title bar and macOS-style menus, making it familiar to Mac users. Screenshot references typically show a clean toolbar, native scrollbars, and support for dark mode if your macOS is set accordingly.

Choosing between the Emacs Mac Port and standard GNU Emacs depends on whether you prioritize native GUI polish and macOS integration over pure command-line usage.

How to open and create files in Emacs on Mac

Understanding how to handle files in Emacs is essential for effective editing. You can open existing files either from within Emacs or directly from the Terminal, and you can create and save new files easily.

  1. To open a file inside Emacs, press Ctrl-x Ctrl-f (written as C-x C-f). You will see a prompt at the bottom asking for the file name. Type the full path or the file name if it is in the current directory, then press Enter. The file's contents will appear in a new buffer.
  2. To open a file from the Terminal, type emacs filename and press Enter. This opens Emacs with that file loaded. If the file does not exist, Emacs creates a new buffer with that name.
  3. To create a new file inside Emacs, press C-x C-f and enter the desired new file name at the prompt, then press Enter. The new buffer will be empty, ready for editing.
  4. After editing or creating a file, save it by pressing Ctrl-x Ctrl-s (C-x C-s). This writes the buffer contents to disk. If it’s a new file, Emacs will create it.
  5. Buffers represent open files or unsaved changes. Switch between buffers using Ctrl-x b (C-x b), typing the buffer name, and pressing Enter. To list all buffers, use Ctrl-x Ctrl-b.
  6. Basic editing includes moving the cursor with arrow keys, deleting text with Backspace, and undoing changes with Ctrl-/ (C-/) or Ctrl-x u. Avoid quitting without saving to prevent data loss.

Beginners often forget to save files after editing. Always confirm the buffer is saved before closing or quitting Emacs. If you try to exit with unsaved changes, Emacs will prompt you to save or discard them.

How to use Emacs on Mac: basic usage and commands

Emacs combines a powerful text editor with a flexible interface composed of multiple modes tailored for different tasks. The main window is divided into buffers showing open files or outputs, with a minibuffer at the bottom for commands and messages.

Start by learning essential keyboard shortcuts that speed up navigation and editing:

  • Ctrl + x Ctrl + f: Open or create a file (you'll see the filename prompt in the minibuffer)
  • Ctrl + x Ctrl + s: Save the current buffer (look for “Wrote” in the minibuffer)
  • Ctrl + g: Cancel the current command or search
  • Ctrl + x k: Close the current buffer
  • Alt + x: Run any Emacs command by name (type the command, e.g., "compile")

To compile code or run scripts, use Alt + x compile. Emacs prompts for the compile command, such as make or gcc filename.c. The compilation output appears in a separate buffer; errors are clickable for quick navigation.

Basic customization can be done by editing your .emacs or init.el file in your home directory. For example, you can enable line numbers by adding (global-display-line-numbers-mode). More extensive customization and packages are documented on the official GNU Emacs manual and popular community sites like EmacsWiki.

How to install Emacs on Mac terminal for command-line usage

Emacs can run both as a graphical application and within the terminal. The terminal version is lightweight and integrates smoothly with command-line workflows, while the GUI offers more macOS-specific features. To use Emacs exclusively in the terminal, you will install and configure it accordingly.

How to install Emacs on Mac terminal for command-line usage – how to install Emacs on Mac
  1. Open your Terminal application on Mac. You should see a command prompt ready for input.
  2. Type emacs --version and press Enter. If Emacs is installed via Homebrew, the version number will display. If not, proceed to install it using brew install emacs, which installs the command-line Emacs without GUI support.
  3. Launch Emacs in the terminal by typing emacs and pressing Enter. You should see the Emacs welcome screen inside your terminal window.
  4. To improve your terminal Emacs experience, configure your terminal emulator to support 256 colors and proper key mappings. For example, in iTerm2, go to Preferences > Profiles > Terminal and enable “Declare terminal as xterm-256color.”
  5. Set Emacs as the default editor for terminal-based tasks by adding export EDITOR="emacs" to your shell configuration file (~/.zshrc, ~/.bash_profile, or ~/.bashrc). After saving, run source ~/.zshrc or the equivalent command to apply changes.
  6. Test the default editor setting by running a command like git commit. The commit message editor should open in terminal Emacs.

By following these steps, you get a fully functional Emacs environment directly in your Mac terminal, optimizing for speed and minimal resource use without macOS GUI dependencies.

Troubleshooting common issues when installing Emacs on Mac

Encountering installation problems with Emacs on Mac is common but usually resolvable with a few targeted steps.

Permission errors during installation

If you see errors like "Permission denied" or "Operation not permitted" during installation, it often means you lack proper write access.

  1. Run the install command with sudo, for example: sudo brew install emacs. You should be prompted for your password, and the command should proceed without permission errors.
  2. If you still get errors, check the permissions of the Homebrew directories by running ls -ld /usr/local /usr/local/bin. Both should be writable by your user or group.
  3. Adjust permissions with sudo chown -R $(whoami) /usr/local if necessary. After this, retry the installation.

Fixing PATH and environment variable issues

If Emacs commands are not found after installation, your PATH variable may not include the correct Homebrew directories.

  1. Check your PATH by running echo $PATH. It should include /usr/local/bin or /opt/homebrew/bin depending on your Mac.
  2. If missing, add the correct path by editing your shell configuration file (e.g., ~/.zshrc or ~/.bash_profile) and adding export PATH=/usr/local/bin:$PATH or export PATH=/opt/homebrew/bin:$PATH.
  3. Reload the shell profile with source ~/.zshrc or restart the Terminal. Then verify with which emacs that the Emacs binary is found.

Resolving conflicts with existing Emacs versions

Conflicts arise if multiple Emacs versions exist, causing unexpected behavior or launching the wrong version.

  1. Check existing versions with which emacs and emacs --version.
  2. If an older Emacs is installed via MacPorts or other package managers, uninstall or disable them by running sudo port uninstall emacs or removing their binaries from PATH.
  3. Prioritize the Homebrew Emacs path by ensuring it appears first in your PATH variable.

Emacs fails to launch or crashes

If Emacs does not open or crashes immediately, consider these steps:

  1. Launch Emacs from Terminal with emacs --debug-init to identify configuration errors in your init file.
  2. Temporarily move your Emacs configuration file (~/.emacs or ~/.emacs.d/init.el) by running mv ~/.emacs ~/.emacs.backup and then relaunch Emacs to check if the issue relates to your config.
  3. Check system logs with Console.app for crash reports related to Emacs to gain insights on the failure.
  4. Reinstall Emacs via Homebrew with brew reinstall emacs to fix corrupted installations.

Following these steps should resolve most common installation and launch issues with Emacs on Mac.

More on this topic

Frequently asked questions

How to install emacs on windows?

To install Emacs on Windows, download the latest installer from the official GNU Emacs website or the GNU FTP mirror. Choose the appropriate 32-bit or 64-bit version, run the installer, and follow the setup prompts. You can then launch Emacs from the Start menu or desktop shortcut.

How to install emacs on ubuntu?

On Ubuntu, you can install Emacs via the terminal using sudo apt update followed by sudo apt install emacs. This installs the stable Emacs version from Ubuntu's repositories. Alternatively, for newer versions, consider using a PPA or building from source.

How to open file in emacs?

In Emacs, open a file by pressing C-x C-f (hold Control and press x, then f), then type the full path or filename and press Enter. If the file exists, it opens; if not, Emacs starts a new buffer for that filename.

How to download emacs?

You can download Emacs from the official GNU Emacs website or trusted mirrors. Choose the package that matches your operating system, such as a DMG for Mac, EXE for Windows, or source code for Linux. Always verify the download source to avoid unofficial versions.

How to create a file in emacs?

To create a new file, open Emacs and press C-x C-f, then enter the new filename including the desired path. Press Enter, and Emacs will open a new buffer for the file. Save it with C-x C-s to write it to disk.

What this guide does not cover and who should look elsewhere

This guide focuses on installation and basic usage on Mac and does not cover advanced Emacs configuration or package management, which can be complex and vary widely by user needs. If you require custom themes, advanced scripting, or extensive plugin setups, consulting dedicated Emacs resources or community forums will be more beneficial.

The single most useful next step is to familiarize yourself with Emacs’ built-in tutorial by opening Emacs and typing Ctrl-h t. This interactive tutorial provides a solid foundation for navigating and editing within Emacs and helps you build confidence before exploring more complex features or configurations.