Emacs Init: Install Package from ELPA, MELPA

By Xah Lee. Date: . Last updated: .


ELPA is new in Emacs 24 (Released 2012-06)

Add Package Repository

put this in your Emacs Init File:

  ;; load elpa package system
  ;; require emacs 24
  (require 'package)
  ;; Add MELPA repository.
  (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 you want:

  1. Alt+x package-install
  2. type the package name, e.g. xah-fly-keys

or run the lisp code:

(package-install 'xah-fly-keys )

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 to see full description.
  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

Key and Command for Package List

list-packages shows result in Major Mode package-menu-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)
d (package-menu-mark-delete)
Mark for deletion (removal of a installed package).
x (package-menu-execute)
start install/uninstall of marked items. (x for execute)
r (revert-buffer)
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.

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).
Run the marked commands on packages.

🛑 WARNING: as of 2017, 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.

Default Package Install 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.

FSF's GNU Emacs package repository. This repository contains package copyrighted by Free Software Foundation.
Non-GNU repository maintained by FSF.
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

Variable. By default, this is t. [see Elisp: Boolean (true false nil)] .
Variable. This determines which packages should be loaded at start-up.

[see Emacs: Show Variable Value]

History of emacs package.el

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

Emacs, packages