Emacs: Install Package from ELPA

By Xah Lee. Date: . Last updated: .

Starting with emacs 24 (year 2012), it comes with a package system called ELPA (Emacs Lisp Package Archive). It lets you install and manage emacs packages. [see Emacs 24.1 Features (released 2012-06)]

Add Package Repository

put this in your Emacs Init File:

(when (>= emacs-major-version 24)
  (progn
    ;; load emacs 24's package system. Add MELPA repository.
    (require 'package)
    (add-to-list
     'package-archives
     '("melpa" . "https://melpa.org/packages/")
     t))

  (when (< emacs-major-version 27) (package-initialize)))

restart emacs.

Install a Package

If you know the name of the package:

(package-install 'xah-fly-keys )

[see Emacs: Evaluate Elisp Code]

If you don't know the name of the package:

  1. Alt+x list-packages.
  2. Find the package you want, move cursor to the line, press Enter. A description pane will pop up.
  3. Put cursor on the pane, press Tab to move cursor to the “Install” button then press Enter.
  4. The package is now installed.
  5. Read the package doc to see what command to start it, if necessary. (no restart is needed)

List Packages

Alt+x list-packages.

emacs list packages 2017 07 02
Emacs list-packages

Install Packages

This list is shown in package-menu-mode. In this mode, here's the most useful keys:

Enter (package-menu-describe-package)
Describe the package under cursor.
i (package-menu-mark-install)
Mark for installation.
u (package-menu-mark-unmark)
Unmark.
d (package-menu-mark-delete)
Mark for deletion (removal of a installed package).
x (package-menu-execute)
For “execute” (start install/uninstall of marked items).
r (package-menu-refresh)
Refresh the list from server.

(For complete list of keys, Alt+x list-packages, then Alt+x describe-mode)

Upgrade Packages

To upgrade packages, just press U x.

package-menu-mark-upgradesU
For any package that has a new version, the installed one will be marked “D” (for delete), and new one will be marked “I” (to install).
package-menu-executex
Run the marked commands on packages.

WARNING: package upgrade may not be reliable. It is better to upgrade one package at a time. Or, just delete the package, then install the latest.

Package Location

packages are installed at ~/.emacs.d/elpa/.

You can go to that directory, open the package you are interested, and read the file header doc.

If you want to remove all external packages, you can delete this entire directory and restart emacs. It is harmless to do so.

Package Repositories

The source of the packages are from package servers. There are several.

http://elpa.gnu.org/
FSF's GNU Emacs package repository. This repository contains package copyrighted by Free Software Foundation.
https://elpa.nongnu.org/
Non-GNU repository maintained by FSF.
https://melpa.org/
MELPA (Milkypostman's Emacs Lisp Package Archive). Emacs community maintained repo. As of 2022-06-08, MELPA has most packages, and updated daily.

Helpful Variables

package-enable-at-startup
By default, this is t (true).
package-load-list
This determines which packages should be loaded at start-up.

[see Emacs: Show Variable Value, List Variables]

history of emacs package.el

The ELPA (aka package.el) emacs package system, is started by Tom Tromey. Marmalade repo (defunct) is started by Nathan Weizenbaum. MELPA is started by Donald Ephraim Curtis (aka milkypostman) http://milkbox.net/ Thank you guys.

ErgoEmacs mascot-s276x226
Buy Xah Emacs Tutorial

Emacs Init

Init Basics

Keys

Font

Text Editing

Completion

File

Restore Things

Backup/AutoSave

Line

Appearance

Misc

Advanced Init Tips

packages