emacs - installation and configuration

Installation

Compile from source

  1. Compiling Emacs 29 https://ryanfleck.ca/2024/compiling-emacs-29/
  2. Compiling Emacs 30 https://ryanfleck.ca/2025/compiling-emacs-30/

For Debian/Ubuntu-based systems:

Install build essentials.

sudo apt-get install build-essential texinfo

Install X11 and GTK+ development libraries.

sudo apt-get install libx11-dev libxpm-dev libjpeg-dev libpng-dev libgif-dev libtiff-dev libgtk-3-dev libncurses-dev

Download the latest version or a specific version of emacs from the links specified here: https://www.gnu.org/software/emacs/download.html

cd /emacs/emacs-26.1/
./configure          #Configure Emacs
make                 #build components using makefile
sudo make install    #Install Emacs

Troubleshooting: You may see errors like this

checking for libXaw... configure: error: No X toolkit could be found.
If you are sure you want Emacs compiled without an X toolkit, pass
  --with-x-toolkit=no
to configure.  Otherwise, install the development libraries for the toolkit
that you want to use (e.g. Gtk+) and re-run configure.

Just use the –with-x-toolkit=no option.

Check the version number

emacs --version

Linux

RPM

sudo dnf install emacs

Arch Linux

pacman -S emacs

In a Linux (Redhat Linux) VDE provided in a corporate environment:

Installing emacs using the command sudo yum install emacs installed an older version of emacs. I think it installed emac 24. How to install the latest version of emacs in a VDE like that?

I tried installing using homebrew but that failed because of a dependency failure. I think it complained that curl was not installed.

What is the process to compile emacs from source?

Debian

Do not use sudo apt install emacs command to install emacs in Debian. By default, the version of emacs that comes is way older than the latest current release.

Instead, use one of these options

  1. Download the tar file and build it manually (painful and tedious)
  2. Use homebrew. That seems to be installing version 30.2 (The latest version at the time of writing this).

In Ubuntu

sudo add-apt-repository universe
sudo apt update
sudo apt install emacs-gtk

In Linux Mint

explorer436@explorer436-Thinkpad-P50:~$ emacs .
Command 'emacs' not found, but can be installed with:
sudo apt install e3           # version 1:2.82+dfsg-2, or
sudo apt install emacs-gtk    # version 1:29.1+1-5ubuntu1
sudo apt install emacs-lucid  # version 1:29.1+1-5ubuntu1
sudo apt install emacs-nox    # version 1:29.1+1-5ubuntu1
sudo apt install emacs-pgtk   # version 1:29.1+1-5ubuntu1
sudo apt install jove         # version 4.17.5.3-1

emacs gtk vs lucid vs nox

https://emacs.stackexchange.com/questions/33065/on-linux-why-should-one-choose-lucid-over-gtk-gui-for-emacs

In Emacs, “gtk”, “lucid”, and “nox” refer to different build configurations and their associated GUI toolkits or lack thereof. gtk provides a graphical interface using the GTK+ toolkit. lucid uses the older, lighter Lucid (Athena) widget set, which some find more stable, especially when forwarding X11. nox is a build without any graphical support, intended for use in a terminal.

Emacs GTK: This is the default graphical Emacs build on many systems, using the GTK+ toolkit for its interface. It’s generally the most modern and visually appealing option, but it can sometimes be resource-intensive and might have issues when forwarding X11 over SSH due to the GTK+ implementation.

Emacs Lucid: This build utilizes the older Lucid (Athena) widget set, which is lighter and can be more stable when forwarding X11 or running in a daemonized environment. It may look less modern and require manual configuration for appearance, but it can be a good choice for remote sessions or situations where stability is paramount.

Emacs NOX: This build is designed for terminal-only use and has no graphical interface or toolkit dependencies. It’s ideal for servers or systems where a GUI is not available or not desired.

Macbook

  1. Run this: brew install --cask emacs to install the UI version.
  2. Run this: brew install emacs This will not install the UI version of emacs. It will install only the terminal version.
  3. Another method that worked for me one time in the past
    1. Installed emacs using homebrew. The command used is brew install --cask emacs
    2. Tried to launch it using the icon in “Applications”
    3. Saw this error “Emacs can’t be opened because Apple cannot check it for malicious software.”
    4. Had to run this to get it installed with Apple’s Gatekeeper disabled. brew reinstall --cask emacs --no-quarantine
    5. Was able to launch emacs successfully

Windows

Download the zip file for the latest version, extract it and use the Application files from the bin folder.

https://www.gnu.org/software/emacs/download.html

Packages

Location of the packages

In Linux, it is /home/explorer436/Downloads/GitRepositories/<any-sub-directories>/.emacs.d/quelpa/melpa/

In Windows, the elpa directory is found in C:\Users\<username>\AppData\Roaming/.emacs.d\elpa\

How to update all packages?

Delete all the local packages and install them again.

  1. Remove everything in ~/.emacs.d/elpa and launch emacs again.
  2. It will pull all the necessary packages.
  3. If some of the packages are not installed properly, the Messages buffer will show the list of them.
  4. Install them manually with M-x package-install <package-name>

How to view the list of all the currently installed packages in Emacs?

If you are using Emacs in one machine, and if you want to set-up the exact same set-up settings in another machine, you need to view the list of installed packages from the package manager.

To see a list of the available packages : Meta x list-packages

Run this command till you find the first row of installed package: Ctrl s installed

Start selecting with Ctrl SPC

Go down till you reach built-in packages. Copy with Meta w. Ctrl x b for new buffer. Paste with Ctrl y. Ctrl x Ctrl s to save file.

Another alternative is, simply copy the .emacs file from this computer to the other computer.

How to add MELPA as another source of packages in addition to GNU’s elpa?

  1. Hint: In order to avoid having to do this multiple times when switching between multiple machines, save the init files in GitHub so that you can just move them from machine to machine.
  2. The alternative is: In a browser, visit MELPA website. Grab the URL for the package archive “https://melpa.org/packages/” Meta x customize-group -> package -> Go to “package archives” -> “INS” to insert a new entry. Provide archive name and archive URL. Set the “State” to “Save for future sessions”.

After making changes to the config to add MELPA as a source of packages, run the following two commands:

  1. Meta x package-refresh-contents (to refresh the list of packages)
  2. Meta x package-install RET (to launch package install mode)
  3. Type the name of the package you are looking for and when you find the package -> RET

Init file

https://www.emacswiki.org/emacs/InitFile

Your init file contains personal EmacsLisp code that you want to execute when you start Emacs.

If you want to look at the contents of the file within Emacs, ~ at the beginning of a file name is expanded to your HOME directory, so you can always find your .emacs file with Ctrl x Ctrl f ~/.emacs

If you are trying to find out where the file is as opposed to looking at the contents of the file:

  1. It should be stored in the variable user-init-file.
  2. Use Meta x describe-variable RET user-init-file RET or Ctrl H v user-init-file RET to check. You can also open it directly by using Meta x eval-expression RET (find-file user-init-file) RET

Where can I find my .emacs file for Emacs running on Linux?

For GnuEmacs, your init file is ~/.emacs, ~/.emacs.el, or ~/.emacs.d/init.el

Where can I find my .emacs file for Emacs running on Windows?

C:\Users\<username>\AppData\Roaming/.emacs

Starting over

If anything goes wrong with the customizations, delete the .emacs file in the home directory and start from scratch or the backed up version of the file again.

When you clone the config files into a new computer, how to make sure all the packages are pulled from MELPA?

M-: (load user-init-file)

What is this doing?

  1. you type it in Eval: prompt (including the parentheses)
  2. user-init-file is a variable holding the ~/.emacs value (pointing to the configuration file path) by default
  3. (load) is shorter, older, and non-interactive version of (load-file); it is not an emacs command (to be typed in M-x) but a mere elisp function

How to resolve start-up issues?

emacs --debug-init

How can I reload .emacs after changing it?

You can use the command load-file (~Meta x load-file~, then press return twice to accept the default filename, which is the current file being edited).

You can also just move the point to the end of any sexp and press Ctrl xCtrl e to execute just that sexp. Usually it’s not necessary to reload the whole file if you’re just changing a line or two.

https://stackoverflow.com/a/2580726

custom-set-variables and custom-set-faces

These blocks are added by the customize interface.

You can move them to a separate file, though, if you like.

Just add this to your ~/.emacs.d/init.el:

(setq custom-file "~/.emacs.d/custom.el")
(load custom-file)

Troubleshooting

Debugging “Error setting nil” in Elisp

https://stackoverflow.com/questions/28086626/debugging-error-setting-nil-in-elisp

Clear custom-set-faces and custom-set-variables and start it again.


Links to this note