Emacs: How to Install Packages Using ELPA, MELPA

Buy Xah Emacs Tutorial. Master emacs benefits for life.
, , …,

Emacs 24 bundled a package system called ELPA (Emacs Lisp Package Archive). It lets you install and manage emacs packages. 〔➤ Emacs 24.1 New Features (released 2012-06)

Quick Start

Add this to your emacs init:

(when (>= emacs-major-version 24)
  (require 'package)
   '("melpa" . "http://melpa.org/packages/")

restart emacs.

  1. Now, call list-packages.
  2. Find the package you want, move cursor to the line press Enter ↵.
  3. press Tab ↹ to the “Install” button and press Enter ↵.
  4. Then, you can start to use the package.

Following are details.

Listing Available Packages

Call list-packages. It'll list available packages, like this:

emacs packages elpa screenshot
Emacs list-packages screenshot

Install Packages

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

(For complete list of keys, call describe-modeCtrl+h m】)

So, for example, i want to install the clojure-mode. I type i to mark it, x to run install. Then, i got the following files in my dir, all automatically byte-compiled and loaded.


and now i can call clojure-mode, and it works right there! (no need to restart, but for some packages, you may need to turn it on.)

Update Packages

To update packages, just press 【U x】.

Installed Packages Location

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

Packages Repositories

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

To add it, put the following in your emacs init file:

(when (>= emacs-major-version 24)
  (require 'package)
   '("melpa" . "http://melpa.org/packages/")

Note: the emacs package system, called ELPA (aka package.el), is started by Tom Tromey. Marmalade is started by Nathan Weizenbaum. MELPA is started by Donald Ephraim Curtis (aka milkypostman) Thank you guys.

Helpful Commands and Variables

New variable package-enable-at-startup. By default, this is t (true).

New variable package-load-list. This determines which packages should be loaded at start-up.

Call describe-function or describe-variable for details.

Flaw of Emacs 24's Package System

Emacs package system isn't perfect. For some modes, you still have to read the package header file and put stuff in your emacs init file for the package to work properly. For detail, see: Emacs 24 Package System Problems.

For a basic understanding of how to install emacs packages manually without package system, see: How to Install Emacs Packages Manually.

Other Emacs Package Systems

There are other emacs package systems. example

Like it? Buy Xah Emacs Tutorial.
blog comments powered by Disqus