I tried to use

M-x package-autoremove

but my .emacs.d directory is still a mess: it's full with several versions of the same package. As side info I use the no-littering package, but when I update packages the old versions are kept in the elpa directory.

I also tried to manually delete old packages. For example if I run

M-x package-list

I get the package list, and at some point in the list I have

no-littering    20190409.1154 installed   help keeping ~/.emacs.d clean

at the end of the list I have

no-littering       1.0.0         obsolete    help keeping ~/.emacs.d clean
no-littering       20190129.2355 obsolete    help keeping ~/.emacs.d clean

and these 3 versions have 3 corresponding folders in the ELPA directory. Therefore I presume that the last 2 entries are old versions, and I mark both of them for deletion (d) and than I execute the deletion with (x). The mini-buffer tells me to run

M-x package-autoremove

which I do, and in fact the corresponding 2 folders in ELPA directory disappeared. But after that when I reload emacs I get an initialization error do to no-littering.

What am I missing?

2 Answers 2


package-autoremove removes packages returned by package--removable-packages:

Return a list of names of packages no longer needed. These are packages which are neither contained in package-selected-packages nor a dependency of one that is.

Old versions is marked for deletion by invoking package-menu-mark-upgrades:

Mark all upgradable packages in the Package Menu. For each installed package with a newer version available, place an (I)nstall flag on the available version and a (D)elete flag on the installed version.

How do you upgrade installed packages?

  • I use M-x auto-package-update-now May 21, 2019 at 15:40
  • Is the auto-package-update-delete-old-versions set to t? Though I don't use auto-package-update.
    – muffinmad
    May 21, 2019 at 19:23
  • no I don't have this package, I'll try it, any particular suggestion to use it? May 21, 2019 at 19:58
  • I don't get it. Where is auto-package-update-now function defined then?
    – muffinmad
    May 22, 2019 at 5:57
  • I just added (require 'auto-package-update) (setq auto-package-update-delete-old-versions t) to my init.el file. I reloaded emacs and ran M-x auto-package-update-now . It updated new versions, old versions are still there. May 22, 2019 at 7:37

I think the following is the best solution I could find.

First I reproduced a fresh install:

  1. I went in ~/.emacs.d/elpa and a noted the list of folders. There were packages with 7 or 8 different version number, it was a mess! With this I got the full list of installed packages

  2. I simply deleted the content of ~/.emacs.d/elpa

  3. I restarted emacs and installed all needed packages with M-x package-list-packages (mark the package to be installed with i install pressing x

  4. Now with fresh install on my machine I added this into the init.el:

(defun package-upgrade-all ()
  "Upgrade all packages automatically without showing *Packages* buffer."
  (let (upgrades)
    (cl-flet ((get-version (name where)
                (let ((pkg (cadr (assq name where))))
                  (when pkg
                    (package-desc-version pkg)))))
      (dolist (package (mapcar #'car package-alist))
        (let ((in-archive (get-version package package-archive-contents)))
          (when (and in-archive
                     (version-list-< (get-version package package-alist)
            (push (cadr (assq package package-archive-contents))
    (if upgrades
        (when (yes-or-no-p
               (message "Upgrade %d package%s (%s)? "
                        (length upgrades)
                        (if (= (length upgrades) 1) "" "s")
                        (mapconcat #'package-desc-full-name upgrades ", ")))
            (dolist (package-desc upgrades)
              (let ((old-package (cadr (assq (package-desc-name package-desc)
                (package-install package-desc)
                (package-delete  old-package)))))
      (message "All packages are up to date"))))

The latter was suggested form here. This is brilliant! Now the following

M-x  package-upgrade-all

magically upgrades all packages and remove the previous installed version with all its auxiliary files. Great!

I tested the function extensively and it works beautifully.

I consider this question solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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