10

I am using emacs 24.4. I have added a large number of installed packages via the M-x list-packages directive over about a year of usage. I would love to export my installed packages list for use elsewhere. Copying my .emacs gives me some errors on startup, which jogs my memory to install certain things. I suspect I could copy the .emacs.d, but that seems like maybe a bad idea.

Is there a procedure or directive I can issue to dump the list of installed packages to a file that can be used to get them on foreign machines easily?

sanimalp
  • 236
  • 2
  • 7
  • 3
    Related: [Synchronize packages between different machines](http://emacs.stackexchange.com/q/408/5296) – npostavs Apr 08 '15 at 22:11
  • 1
    Copying your `.emacs.d` directory (or preferably putting it under version control) is generally a good idea. (It's also sensible to rename `~/.emacs` to `~/.emacs.d/init.el` if you decide to do this.) – phils Apr 09 '15 at 01:17

3 Answers3

5

The directory ~/.emacs.d/elpa contains all packages installed with list-packages. You can copy this directory over.

I would probably also run something like (byte-recompile-directory "~/.emacs.d/elpa" 0 t) (0 means don't ask, t means force recompile) to byte-recompile everything because I believe there is some incompatibility of byte-compiled files between Emacs versions.

nanny
  • 5,704
  • 18
  • 38
4

I had a look through the package.el file and found the variable package-alist. This seems to be a list of all installed packages including packages that are required by packages that you have installed.

If all you want is a list of the package names installed the the following code will write out the names of the packages from this list to the *Messages* buffer.

(dolist (p1 (sort (mapcar 'symbol-name (mapcar 'car package-alist)) 'string<))
  (message "%s" p1))

I'm no Lisp programmer so I'm sure somebody can write a much better version of this code.

I've also started to use the use-package code with the :ensure t option in order to install all my packages on a new PC.

Colin Bell
  • 619
  • 6
  • 8
2

One way of doing could be to install package if not already installed, you should update your init file, and add those lines:

(defvar my-packages
  '(color-theme db-pg db kv magit-push-remote magit-tramp
                magit git-rebase-mode git-commit-mode pg
                pretty-lambdada projectile pkg-info epl dash
                python-mode rich-minority s yasnippet yasnippet-bundle
                use-package key-chord undo-tree guide-key move-text
                openwith ack ag aggressive-indent nginx-mode multiple-cursors
                smartparens with-editor haskell-mode)
  "A list of packages to ensure are installed at launch.")

(defun my-packages-installed-p ()
  (loop for p in my-packages
        when (not (package-installed-p p)) do (return nil)
        finally (return t)))

(unless (my-packages-installed-p)
  ;; check for new packages (package versions)                                  
  (package-refresh-contents)
  ;; install the missing packages                                                                               
  (dolist (p my-packages)
    (when (not (package-installed-p p))
      (package-install p))))

Modify the my-packages variable and add/remove the package you want to be installed. M-x describe-variable package-activated-list will give you the list of your currently installed package.

After that, the only thing to share is your init file. I hope it will help.

verdammelt
  • 367
  • 3
  • 10
Nsukami _
  • 6,341
  • 2
  • 22
  • 35
  • Oops i see that you did answer how to dump the list. Perhaps that should be made more prominent in your answer? – verdammelt Apr 09 '15 at 00:42