I've repurposed some code to show me a list of packages that I have installed which have upgrades available.

Currently I'm running package-refresh-contents when I start-up Emacs and then display the list of upgrade-able packages. This however locks my Emacs up until the refresh completes.

Is there a way to run package-refresh-contents as a background process (inside Emacs, but possibly also as some kind of cronjob which would only reflect in Emacs sessions opened after said job has finished running) which doesn't interfere with my ability to carry on working?

  • 2
    C-h f suggests package-refresh-contents can run in the background without blocking Emacs UI.
    – xuchunyang
    Jul 3, 2019 at 15:26
  • Thanks again. If you make this an answer I'm more than happy to accept it. Else I'll compile one later this evening.
    – alecvn
    Jul 3, 2019 at 15:46
  • 1
    Feel free to do that. I've not tried the ASYNC argument and not sure how it works.
    – xuchunyang
    Jul 3, 2019 at 16:02

2 Answers 2


As @xuchunyang pointed out, package-refresh-contents takes an optional argument which allows it to be called asynchronously.

Therefor one can call it programmatically like:

(package-refresh-contents t)

This works perfectly and unlike a normal call to package-refresh-contents made in your init.el, which would lock up your Emacs, you can continue as normal while your package list is refreshed in the background.

For my particular use case however - having my contents refreshed before launching Emacs in the morning - I decided to write a bash script which I run via cronjob every night at midnight. The contents of my script is:


emacs -nw -Q --eval="(package-refresh-contents)" &
sleep 100
kill -9 $PID
exit 0

You could take Alecvn answer one step futher by running emacs in batch mode. That way you don't have to mess around with PIDs or guessing timeouts.

emacs -nw -Q --eval="(package-refresh-contents)" -batch -kill

The -kill option allows emacs to exit without confirmation

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.