I'm using use-package in my init.el for all my package installations and configuration. I thought specifying :ensure t
in use-package would make sure I always have the latest versions installed. But when I did M-x package-list-packages
the minibuffer tells me I have a number of package updates waiting. Isn't it enough to specify :ensure t
in use-package, do I have to manually check for and install updates using M-x package-list-packages
? What is the best way to handle updates when using use-package?
2 Answers
The :ensure
option in use-package
does not automatically keep packages up to date. It ensures that the package is installed. This might be useful if you pull your Emacs config on to a new machine (or are using it across several machines), because when you start up all your required packages would get installed.
You'll still need to deal with installing updates.
-
1The reason I've heard as to why that's the case is because updating packages can break them, so it would regress in functionality.– zckCommented Mar 31, 2017 at 16:58
-
1@zck I think it's more that
use-package
is meant to provide a quick startup and checking for updates would be slow. Also, the author ofuse-package
doesn't use package.el packages, any related features (like:ensure
) were tacked on afterwards by other users. In the original design, all packages are considered optional, your init.el just skips configuration of missing packages.– npostavsCommented Mar 31, 2017 at 17:57
I use auto-package-update
to automatically update packages.
(use-package auto-package-update
:ensure t
:config
(setq auto-package-update-delete-old-versions t
auto-package-update-interval 4)
(auto-package-update-maybe))
With that setup, packages will be updated every 4
days, and the old packages will be removed.
-
1You might want to add this as an answer here: emacs.stackexchange.com/questions/31872/…– glucasCommented Apr 3, 2017 at 18:10
-
It appears to me that the call to ` (auto-package-update-maybe)` is not the value of one of use-package's keyword options. Should it perhaps be wrapped in a progn as part of the :config, like this: ``` (use-package auto-package-update :ensure t :config (progn (setq auto-package-update-delete-old-versions t auto-package-update-interval 4) (auto-package-update-maybe))) ```– malcookCommented Nov 1, 2019 at 17:43
-
should I do
(when (not package-archive-contents) (package-refresh-contents))
before running this?– alperCommented Oct 3, 2020 at 1:41