How to rebuild ELPA packages after upgrade of Emacs

EmacsElpa

Emacs Problem Overview


I just upgraded GNU Emacs from 23 to 24 on MacOS and some ELPA installed packages stopped working. One of them is AucTeX. Deleting it and reinstalling it through the package manager made it work again, but I don't want to do this by hand for every package. I'm slightly confused that I find nothing about that on the Internet.

Don't the .elc need to be recompiled for a new version of Emacs? Why isn't this a feature of package.el?

Emacs Solutions


Solution 1 - Emacs

You do not need to re-install all packages. The packages itself are likely fine, however, they need to be re-compiled, because Emacs Lisp byte code is generally not compatible across major versions.

To re-compile all packages, type M-: (byte-recompile-directory package-user-dir nil 'force). After restarting Emacs, packages should work fine again.

Solution 2 - Emacs

This works for me on Emacs 25.1 and 26:

(defun package-reinstall-all-activated-packages ()
  "Refresh and reinstall all activated packages."
  (interactive)
  (package-refresh-contents)
  (dolist (package-name package-activated-list)
    (when (package-installed-p package-name)
      (unless (ignore-errors                   ;some packages may fail to install
                (package-reinstall package-name))
        (warn "Package %s failed to reinstall" package-name)))))

Solution 3 - Emacs

The variable package-activated-list holds the list of packages we're interested in. So we just need to install each one again. We don't need to explicitly delete them; calling package-install will blow away an old version.

Put this code in a scratch buffer and evaluate it (that is, put your cursor at the end, and press C-x C-e):

(dolist (package-name package-activated-list)
  (package-install package-name))

Solution 4 - Emacs

my recipe after emacs 25:

  1. in .emacs (define your packages list):

> (custom-set-variables > '(package-selected-packages > (quote > (browse-kill-ring helm undo-tree use-package)))

  1. in a terminal:

> $ rm -rf ~/.emacs.d/elpa/*

  1. in emacs:

> (progn (package-refresh-contents) > (package-install-selected-packages) > (byte-recompile-directory package-user-dir nil 'force))

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
QuestionThomasView Question on Stackoverflow
Solution 1 - EmacslunaryornView Answer on Stackoverflow
Solution 2 - EmacsNordlöwView Answer on Stackoverflow
Solution 3 - EmacszckView Answer on Stackoverflow
Solution 4 - Emacs象嘉道View Answer on Stackoverflow