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.

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.

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.

Is the auto-package-update-delete-old-versions set to t? Though I don't use auto-package-update.
– muffinmadMay 21 at 19:23

no I don't have this package, I'll try it, any particular suggestion to use it?
– PinkCollinsMay 21 at 19:58

I don't get it. Where is auto-package-update-now function defined then?
– muffinmadMay 22 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.
– PinkCollinsMay 22 at 7:37