I have found the following lisp code in an init.el file. I am wondering if this code logic is correct. I am learning Elisp and have reviewed the documentation and searched Stack Overflow. If this is too basic a question to ask, please direct me to a source:

(when (not package-archive-contents)

My understanding is that logic says that if there is no package-archive file, then refresh the cache .

Following are my questions:

  1. Does Emacs download a cache for each of the sources in the package-archive list?
  2. If package-refresh-contents is called only if the cache is absent, how do we (Emacs) keep the archive current? Do we have to manually use M-x package-refresh-contents?
  • 1
    Great question, I am currently running into a completely related issue. I have configured Emacs to automatically install packages by adding them to the package-selected-packages list and then calling the package-install-selected-packages function. Is there a way to make Emacs automatically run (package-refresh-contents) when it identifies that new packages ought to be installed? Currently, Emacs freezes when a package is not found in the cache simply because the cache is not updated. Commented Dec 9, 2019 at 14:06

1 Answer 1


package-archive-content is used by use-package . it is the utility for installing packages. The snippet that you are quoting indeed refreshes the content or the list-packages in case it is empty.

It isn't a cache, it is only a list.

To update the list you need to manually call M-x list-packages and update it with U.

This update process might take a while therefore it shouldn't really be part of the init file for every time you fire up Emacs.

  • <f1> v package-archive-contents RET: "Cache of the contents of the Emacs Lisp Package Archive.[...]". To some extent, this is just a question of semantics of course, what exactly do you mean when you say "cache".
    – npostavs
    Commented Jun 17, 2018 at 13:49
  • @npostavs I meant if Emacs will download a copy of the Emacs Lisp Archive. It looks from your response that is what it does.
    – Vinod
    Commented Jun 18, 2018 at 3:47
  • Ah, I think the confusion here is that this variable is a cache of the package list (i.e., it is indeed "only a list" and also a cache).
    – npostavs
    Commented Jun 18, 2018 at 12:17
  • I.e. it is the "contents" in the sense of a "table of contents" at the beginning of a book. It's the list of what is available, rather than "the whole book".
    – phils
    Commented Dec 14, 2018 at 23:54

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.