Emacs: How to Install Packages Using ELPA, MELPA
Starting with emacs 24, it comes with a package system called ELPA (Emacs Lisp Package Archive). It lets you install and manage emacs packages. 〔►see Emacs 24.1 New Features (released 2012-06)〕
Add this to your emacs init:
(require 'package) ;; You might already have this line (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/")) (when (< emacs-major-version 24) ;; For important compatibility libraries like cl-lib (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))) (package-initialize) ;; You might already have this line
- Find the package you want, move cursor to the line press Enter ↵.
- press Tab to move cursor to the “Install” button then press Enter ↵.
- Then, you can start to use the package.
Following are details.
Listing Available 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
describe-mode 【Ctrl+h m】)
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 or restart emacs.)
To upgrade packages, just press 【U x】.
package-menu-mark-upgrades【U】 → 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-execute【x】 → run the marked commands on packages.
WARNING: package upgrade is not reliable. It is better to upgrade one package at a time. First delete the package, then install the latest.
Installed Packages Location
New packages are installed at
If you want to remove all external packages, you can delete this entire directory and restart emacs. It is harmless to do so.
The source of the packages are from package servers. There are several.
- http://elpa.gnu.org/ Default. Official GNU Emacs package repository. This repository contains the minimal set, and each package is owned by Free Software Foundation.
- http://marmalade-repo.org/ Marmalade. More extensive number of packages.
- https://melpa.org/ MELPA. As of , MELPA has most packages, and updated daily.
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
package-enable-at-startup. By default, this is
package-load-list. This determines which packages should be loaded at start-up.
describe-variable for details.
How to Install Emacs Package Manually
Emacs Customize Topic
- How to Set Emacs's User Interface
- Emacs: How to Install Packages Using ELPA, MELPA
- How to Install Emacs Package Manually
- Emacs: How to Define Keys
- Emacs: M-x customize Tutorial
- Emacs: Set File to Open in a Major Mode
- Organize Emacs Init File in 5 Minutes
- Emacs: Byte Compile Elisp Files
- Emacs: What's Hook?
- Emacs: Set Environment Variables within Emacs