I tried to install emacs and in an attempt to install MELPA, tried:

(this is my init.el file)

(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))

(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
                    (not (gnutls-available-p))))
       (proto (if no-ssl "http" "https")))
  (add-to-list 'package-archives
               (cons "melpa" (concat proto "://melpa.org/packages/")) t))

When I tried running the following commands M-x package-initialize then M-x package-refresh-contents, it said that it Failed to download 'gnu' archive. Is there anyway of getting around this?

I'm using MacOS and using emacs version 26.2.

3 Answers 3


Add the following before package-initialize:

(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")

This is apparently a bug in Emacs 26.2 for MacOS. I found this solution in this reddit thread.

  • Not just macOS, see debbugs.gnu.org/36725#8, debbugs.gnu.org/34341. Though the bug seems only to trigger with newer libgnutls (probably 3.6.3+).
    – npostavs
    Commented Jul 23, 2019 at 0:06
  • Yes, adding this line in .emacs file solved my problem. Thanks!
    – john
    Commented Aug 26, 2019 at 7:47

First of all run emacs with --debug-init from your terminal and check if it complains about being unable to verify the elpa archive due to an invalid key. If that is the case, copy the public key displayed to you.

I ran into this problem because the GPG keys used by the ELPA package manager to verify authenticity of packages downloaded from the GNU ELPA archive have a limited validity in time (for example, the first key was valid until Sep 2019 only).

If your keys are already too old, causing signature verification errors when installing packages you can do the following:

gpg --homedir ~/.emacs.d/elpa/gnupg --receive-keys C433554766D3DDC64221BFAA066DAFCB81E42C40

You should replace the key with the value you copied from the debug log

I found this package to hopefully avoid this problem when the certificates change the next time.

  • The gpg command fails with the following error: gpg: keyserver receive failed: General error . Commented Aug 4, 2020 at 19:58

Another potential problem is that gnutls-cli, which Emacs may be trying to use to initiate the TLS connection, just may not be installed. Unfortunately, if this is the case, the error message produced by Emacs gives no indication of this. If this is indeed the problem, then on a Debian-like system you need to install gnutls-bin, whereas on a RedHat-like system the package is called gnutls-utils.

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.