Emacs: How to Install Packages Using ELPA, MELPA, Marmalade

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 auto-update and manage emacs packages. 〔➤ New Features in Emacs 24.1

Quick Start

Add this to your emacs init:

(when (>= emacs-major-version 24)
  (require 'package)
  (package-initialize)
  (add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
  )

restart emacs.

Now, just call list-packages. Find the package you want, move cursor to the line, press Enter ↵, then click Install. 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.

~/.emacs.d/elpa/clojure-mode-1.7.1:
clojure-mode-autoloads.el
clojure-mode-pkg.el
clojure-mode-pkg.elc
clojure-mode.el
clojure-mode.elc

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)
  (package-initialize)
  (add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
  )

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.

Other Emacs Package Systems

There are other emacs package systems. example

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