7

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?

Mikael Springer
  • 513
  • 3
  • 13

2 Answers2

14

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.

cslux
  • 421
  • 2
  • 5
  • 1
    You might want to add this as an answer here: http://emacs.stackexchange.com/questions/31872/how-to-update-packages-installed-with-use-package – glucas Apr 03 '17 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))) ``` – malcook Nov 01 '19 at 17:43
  • should I do `(when (not package-archive-contents) (package-refresh-contents))` before running this? – alper Oct 03 '20 at 01:41
7

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.

glucas
  • 20,175
  • 1
  • 51
  • 83
  • 1
    The reason I've heard as to _why_ that's the case is because updating packages can break them, so it would regress in functionality. – zck Mar 31 '17 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 of `use-package` doesn't use package.el packages](https://github.com/jwiegley/dot-emacs/blob/master/init.el), 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. – npostavs Mar 31 '17 at 17:57