An Emacs installation can come in two types nowadays. The first type is an in-terminal installation, which is basically the way Emacs has been run for decades from the command line. The second type is the GUI installation, which has become prominent in the last 10-15 years or so. The installations of each type on MacOS are slightly different. Let's try each one.
The easiest way to install in-terminal Emacs (version 27.0 at the time of this writing) is to execute the following commands at the command line:
brew tap daviderestivo/emacs-head brew install emacs-head --HEAD --with-cocoa
This will install Emacs. However, the Homebrew might ask you to run some linking commands before it actually works. After you have done the linking, you can check the new installation via:
(base) user:09/29/21:~$emacs --version GNU Emacs 27.2 Copyright (C) 2021 Free Software Foundation, Inc. GNU Emacs comes with ABSOLUTELY NO WARRANTY. You may redistribute copies of GNU Emacs under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING.
That is all there is to installing an in-terminal Emacs using the Homebrew package manager.
GUI Emacs from Scratch
Let's try installing a GUI Emacs (version 28, unreleased, at the time of this writing) by compiling the source code. Version 28 of Emacs is attractive because it includes compilation of elisp code to native code, which drastically speeds up the execution. At the time of this writing, this feature has not been included in the official Emacs releases. Hence, the need to compile the code from scratch to get a working Emacs that is fast. For more information, see here.
First, execute the following commands. The cloning might take about 15 minutes.
cd ~ mkdir tmp cd tmp git clone https://git.savannah.gnu.org/git/emacs.git cd emacs
The above commands have cloned the Emacs source code for us. Let us configure it.
When running the above commands, make sure there are no errors (warnings are typically fine).
Then run the make
make bootstrap make make install
Similarly, make sure there no errors when each command is executed. If all is clear, then your Emacs has been built. You can now move it to your Applications directory:
mv nextstep/Emacs.app /Applications/
Try launching the Emacs from the Applications directory. You should see something like this
For more information about Emacs and MacOS installation of Emacs, see the excellent documentation.