4

I'm currently using Ubuntu 18.04, and trying out Emacs for the first time. However, whenever I run the command package-refresh-contents, I get the the follow error:

Failed to download 'gnu' archive

This is my ~/.emacs.d/init.el file:

(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
;(setq package-check-signature nil)

; Set up melpa package repository
(require 'package)
(setq package-enable-at-startup nil)

(add-to-list 'package-archives
         '("gnu", "https://elpa.gnu.org/packages/")
         '("melpa", "https://melpa.org/packages/"))

(package-initialize)

These are the steps I've tried so far:

  1. Upgraded from Emacs 26.2 to 26.3. According to this Reddit thread, this was supposedly fixed in Emacs 26.3. Since I'm using Kelley PPA to download Emacs, I had to upgrade from Ubuntu 16.04 to 18.04 to get Emacs 26.3, and it still didn't fix the issue.
  2. Set (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3") as suggested here.
  3. Set (setq package-check-signature nil) as suggested here.
  4. Changed the URLs from https to http.

I've found no other suggestions when I searched online. Any help would be appreciated.

Updating with error message printed in Messages buffer when running the command package-refresh-contents after starting emacs with the flag --debug-init:

For information about GNU Emacs and the GNU system, type C-h C-a.
Importing package-keyring.gpg...done Contacting host: elpa.gnu.org:443
gnutls.el: (err=[-50] The request is invalid.) boot: (:priority NORMAL:-VERS-TLS1.3 :hostname elpa.gnu.org :loglevel 0 :min-prime-bits 256 :trustfiles (/etc/ssl/certs/ca-certificates.crt) :crlfiles nil :keylist nil :verify-flags nil :verify-error nil :callbacks nil)
Failed to download ‘gnu’ archive. [2 times]
You can run the command ‘package-refresh-contents’ with M-x pa-r- RET
Failed to download ‘gnu’ archive.

Updating with error message after removing the gnutls-algorithm-priority setting:

For information about GNU Emacs and the GNU system, type C-h C-a.
delete-backward-char: Text is read-only [4 times]
Importing package-keyring.gpg...done
Contacting host: elpa.gnu.org:443 [2 times]
Failed to download ‘gnu’ archive.
You can run the command ‘package-refresh-contents’ with M-x pa-r- RET
Failed to download ‘gnu’ archive.

Updated with debugger info after running command toggle-debug-on-error and then running package-refresh-contents:

Debugger entered--Lisp error: (wrong-type-argument stringp ((\, "https://elpa.gnu.org/packages/")))
string-match("\`https?:" ((\, "https://elpa.gnu.org/packages/")) nil)
package--download-one-archive(("gnu" (\, "https://elpa.gnu.org/packages/")) "archive-contents" nil)
package--download-and-read-archives(nil)
package-refresh-contents()
funcall-interactively(package-refresh-contents)
call-interactively(package-refresh-contents record nil)
command-execute(package-refresh-contents record)
execute-extended-command(nil "package-refresh-contents" "package-refr")
funcall-interactively(execute-extended-command nil "package-refresh-contents" "package-refr")
call-interactively(execute-extended-command nil nil)
command-execute(execute-extended-command)

gjvatsalya
  • 141
  • 1
  • 3
  • 1
    Do you get a backtrace if you use `emacs --debug-init`? Is there any text in the `*Messages*` buffer? – npostavs Oct 12 '19 at 02:07
  • @npostavs I've updated the question with the error message printed in the Messages. I'm not able to figure out what I need to do based on the error message though. – gjvatsalya Oct 14 '19 at 15:06
  • I think that message indicates your libgnutls version is too old to understand `"NORMAL:-VERS-TLS1.3"`, try removing that setting (and it shouldn't be needed in Emacs 26.3 regardless). – npostavs Oct 14 '19 at 15:11
  • @npostavs I removed `(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")`, and I still get the same error. Although the Messages buffer just has less info now. I've updated the question again with what's printed in the Messages buffer. – gjvatsalya Oct 14 '19 at 15:16
  • Oh, I missed that this is error is in response to running a command, so `--debug-init` won't help. Try `M-x toggle-debug-on-error` before `package-refresh-contents` instead. – npostavs Oct 14 '19 at 18:17
  • @npostavs Updated the question again with the debugger info. Admiteddly, I don't know lisp enough to understand what's going on here. – gjvatsalya Oct 14 '19 at 18:25
  • @npostavs I figured it out. When doing `add-to-list`, I had `'("gnu", "https://elpa.gnu.org/packages/")`. I just changed it to `'("gnu" . "https://elpa.gnu.org/packages/")` and it then worked. Thank you so much for your help! – gjvatsalya Oct 14 '19 at 18:34
  • yeah, I had just noticed that. Also, you need a separate `add-to-list` call for the melpa item, `add-to-list` only adds one item at a time. – npostavs Oct 14 '19 at 18:36
  • That's good to know. I'll update it. – gjvatsalya Oct 14 '19 at 18:43

1 Answers1

0

Thanks to @npostavs, who provided the solution in their comments. Here's the fixed init.el file, for quick and easy reference:

;(setq package-check-signature nil)

; Set up melpa package repository
(require 'package)
(setq package-enable-at-startup nil)

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

(package-initialize)
andycraig
  • 101
  • That doesn't fix it for me; I still get Failed to download 'gnu' archive. This is under Zorin 15.3 running the supplied Emacs 25.2.2 which is saying Failed to verify signature archive-contents.sig: No public key for 066DAFCB81E42C40 created at 2021-01-24T22:05:02+0000 using RSA Command output: gpg: Signature made Sun 24 Jan 2021 10:05:02 PM GMT gpg: using RSA key C433554766D3DDC64221BFAA066DAFCB81E42C40 gpg: Can't check signature: No public key – Peter Flynn Jan 27 '21 at 21:29