InstallingPackages

Basic commands:

M-x package-install
M-x package-delete

ELPA is the most common method of installing packages (as of Emacs 24).

Additional package archives such as MELPA exist to supplement what is in GnuELPA.

Discovering packages

Type M-x list-packages to open the package list. Press ‘i’ to mark for installation, ‘u’ to unmark, and ‘x’ to perform the installation. Press ‘RET’ to read more about installing and using each package.

The list can be easily filtered by name, description, status, keywords and more, using the keybindings starting with ‘/’. The corresponding commands have names starting with ‘package-menu-filter-’. For example, to filter by status use keybinding ‘/s’ or ‘M-x package-menu-filter-by-status’. ‘//’ removes all filters.

You may want to start by installing the paradox package. This will allow you to use the command paradox-list-packages, which among other things gives the ability to sort package list by GitHub popularity. Starting with the most popular packages is a good way to find the most useful and effective ones.

If there is a package that you want, but it’s not listed, you may need to add another package source.

Adding a package source

By default, Emacs 24 or later is set up with the GnuELPA package archive. If you need to add more sources, include Emacs code like this to your InitFile:

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))

Alternatively, you can use the Customize interface with the command ‘M-x customize-variable package-archives’ .

The value will depend on the package source you want to add. See ELPA and MELPA for more information.

Moving into a New System

If you move to a different system and you would like to quickly install all of your previously installed packages, look into ‘M-x package-install-selected-packages’. If you use UsePackage, the :ensure t property will tell Emacs to install a package if it hasn’t already been installed.

Shortlisting Packages

If you are looking for a package or a feature, it is more likely that it is already in MELPA. As on April 2019, MELPA has upwards of 4000 packages. So, start your search for a package in that repository. Alternately, you can shortlist packages right within Emacs using the `tablist` package. See How I shortlist add-ons for my Emacs: Introducing `tablist` for a nice tutorial on how you can do this.

Working with network proxies

If you are behind a firewall that requires the use of a proxy, you may need to configure HTTP or HTTPS proxies in order to list or install packages. Here is sample code from Stack Overflow. Replace the proxy information with whatever your network requires.

    (setq url-proxy-services
       '(("no_proxy" . "^\\(localhost\\|10.*\\)")
         ("http" . "proxy.com:8080")
         ("https" . "proxy.com:8080")))
    (setq url-http-proxy-basic-auth-storage
        (list (list "proxy.com:8080"
                    (cons "Input your LDAP UID !"
                          (base64-encode-string "LOGIN:PASSWORD")))))

Using and configuring packages

Many packages come with instructions on installation and use. These can be viewed in the package manager by pressing ‘RET’ on the package line.

UsePackage can make it easier for you to organize your package-related configuration. For more information, see its homepage: https://github.com/jwiegley/use-package

For more inspiration and examples, look into the source of the Emacs starter configurations such as the ones found here.

Installing individual Emacs Lisp files

Some Emacs Lisp libraries or configuration snippets not available as packages. To install them, see LoadPath.

Configuring packages

The autoloads for installed packages will automatically be loaded after your InitFile has finished processing, so common commands will be available without any additional configuration. You can also use Customize to change the settings for your installed files.

If you need to configure other settings in your InitFile and you’re running into undefined functions or variables, you can use (package-initialize) to set up the load-paths and autoloads for installed packages. Then you can use (require 'package-name) to fully load the package, (with-eval-after-load "package-name" ...) or (eval-after-load 'package-name ...) to run code after a package is loaded, or something like the UsePackage macro to organize your package-related configuration.

Error: file not found while loading a package

While installing a package ‘foo’, you may get an error like:

file-error "http://melpa.org/packages/foo-20161202.1657.tar" "Not found"

In this case, you may have to update some internal variable corresponding to the cached list of packages with either:

M-x package-refresh-contents

or, from within M-x list-packages, press U to update the list. After that, consider to press x to upgrade packages to the latest version.

As this update process might take a while, it shouldn’t really be part of the init file every time you fire up Emacs.


CategoryPackaging