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?

  • 2
  • 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 9 '15 at 1:17
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.

  • I have used this strategy several times since asking this question. Thanks for the input. – sanimalp Jun 16 '16 at 16: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.

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.

  • Oops i see that you did answer how to dump the list. Perhaps that should be made more prominent in your answer? – verdammelt Apr 9 '15 at 0:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.