How to save a list of all the installed packages in Emacs 24?

EmacsEmacs24Dot EmacsEmacs Prelude

Emacs Problem Overview


I am using prelude as a base Emacs configuration. I have installed lots of packages from the package manager, and I want to use my settings on another machine.

I don't want to carry the installed packages and also I don't want to create a list manually.

What is the way of saving a list all the installed packages into prelude-package.el or any other file so that when I take this configuration to my other machine, they automatically get installed there on first use?

Emacs Solutions


Solution 1 - Emacs

You can get a list of currently installed packages (excluding built in packages) from the variable package-activated-list. To automatically install them on startup, see this question: https://stackoverflow.com/questions/10092322/how-to-automatically-install-emacs-packages-by-specifying-a-list-of-package-name

More specifically, if you do C-h v package-activated-list, copy the value shown, and insert it as the value of prelude-packages, emacs will automatically ensure those packages are installed on start up.

Solution 2 - Emacs

The canonical methodology is the best (described by ataylor). Here is a more clumsy method.

M-x list-packages. C-s installed till you find the first row of installed package. Start selecting with C-SPC. Go down till you reach built-in packages. Copy with M-w. C-x b for new buffer. Paste with C-y.C-x C-s to save file.

Only advantage that I see is this is a tad more descriptive. Showing a small description of your packages. useful when you install some packages and forget about it.

Solution 3 - Emacs

As mentioned at https://stackoverflow.com/questions/10092322/how-to-automatically-install-emacs-packages-by-specifying-a-list-of-package-name, it would be better to also record the version of the package you need. In order to do so, you can use the following function:

(defun list-packages-and-versions ()
  "Returns a list of all installed packages and their versions"
  (mapcar
   (lambda (pkg)
     `(,pkg ,(package-desc-version
                (cadr (assq pkg package-alist)))))
   package-activated-list))

That will give you a list of (NAME VERSION) pairs. Unfortunately, I haven't been able to find a way to install a specific version of a package. It seems package.el always grabs the latest available. What I'm doing now is:

(defun install-packages-with-specific-versions (package-version-list)
  "Install the packages in the given list with specific versions.
PACKAGE-VERSION-LIST should be a list of (NAME VERSION) lists,
where NAME is a symbol identifying the package and VERSION is
the minimum version to install."
  (package-download-transaction
   (package-compute-transaction () package-version-list)))

I've written a longer function to install packages matching the exact version number, but it fails because package.el by default only retrieves the latest versions available for each package. gist

Solution 4 - Emacs

As described above, using emacs normal mode. Here another the evil-mode way of doing it:

M-x list-packages; /installed (they will be highlighted); v (for visual-mode); j (to select them); y (to copy them); open a new buffer and paste them.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionA.K.View Question on Stackoverflow
Solution 1 - EmacsataylorView Answer on Stackoverflow
Solution 2 - Emacsknight17View Answer on Stackoverflow
Solution 3 - EmacsFelipeView Answer on Stackoverflow
Solution 4 - EmacsAchyllesView Answer on Stackoverflow