I’m keeping this configuration synchronized between two machines. For most changes simply pushing the change to my Emacs Reboot GitHub repo and pulling it on the other machine is all I need. But when the customizations depend on a certain package being installed, the configuration breaks on the other machine until I manually install the package.

Today I add a customization which ensures all needed packages are installed at the time Emacs starts up:

(setq package-archives 
      '(("gnu" . "http://elpa.gnu.org/packages/") 
        ("marmalade" . "http://marmalade-repo.org/packages/") 
        ("Tromey" . "http://tromey.com/elpa/")))
(package-initialize)
(setq abg-required-packages 
      (list 'xml-rpc 'magit 'gh))
(dolist (package abg-required-packages)
  (when (not (package-installed-p package))
    (package-refresh-contents)
    (package-install package)))

This code is pretty straightforward: first, define the list of package archives to search, and make sure the package system is initialized. Then define a list of needed packages, and iterate over the list, installing the ones which are missing from this Emacs.

[boilerplate bypath=”emacs-reboot”]

Published by Avdi Grimm

6 Comments

  1. I have:

        (defun rwd-require-package (name)
          (or (package-installed-p name) (package-install name)))

    Which allows me to put the package requirement near its use rather than have a centralized list of stuff that may fall out of sync with my needs.

    Reply
  2. I highly recommend you try el-get, the meta package manager for emacs. You can install packages from ELPA, apt, vcs repositories (git, svn, bzr), and even EmacsWiki.

    Reply
  3. (package-refresh-contents) probably can be placed outside of the loop.

    (package-refresh-contents)(dolist (package abg-required-packages)  (when (not (package-installed-p package))    (package-install package)))

    Reply
  4. You can also achieve it by using the packages like Cask and pallet. Cask is similar to Bundler in Ruby. It produces a file called Cask with all your installed packages listed in it. Pallet keeps Cask file in sync when you install/remove packages.

    Here is the difference in my emacs config https://github.com/fsproru/dotfiles/commit/f410216e63c56da6982485cd125d1674359e368f

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *