I am trying to install packages/modes from melpa on my emacs27.1, but I am unable to do so. If I run M-x package-refresh-contents , I get the following error :

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 nil :trustfiles (/etc/ssl/certs/ca-certificates.crt) :crlfiles nil :keylist nil :verify-flags nil :verify-error nil :callbacks nil)
Failed to download ‘gnu’ archive.
gnutls.el: (err=[-50] The request is invalid.) boot: (:priority NORMAL:-VERS-TLS1.3 :hostname stable.melpa.org :loglevel 0 :min-prime-bits nil :trustfiles (/etc/ssl/certs/ca-certificates.crt) :crlfiles nil :keylist nil :verify-flags nil :verify-error nil :callbacks nil)
Package refresh done
Failed to download ‘melpa-stable’ archive.
You can run the command ‘package-refresh-contents’ with M-x pa-r- RET
Failed to download ‘melpa-stable’ archive.

My emacs init file has the following commands corresponding to this function:

(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
(require 'package)
(add-to-list 'package-archives
             '("melpa-stable" . "https://stable.melpa.org/packages/") t)

By tracing a little I thought the error might be due to GnuTLS and it could not connect to the internet. So I tried M-x eww RET https://www.wikipedia.org/ RET, it stops at Contacting host: www.wikipedia.org:443 and does not load anything.

Prior to this, I was running on emacs25 (updated to 27.1 thinking this error would go away), and when I ran M-x eww RET https://www.wikipedia.org/ RET on emacs25, I would get

Contacting host: www.wikipedia.org:443
gnutls.el: (err=[-50] The request is invalid.) boot: (:priority NORMAL:-VERS-TLS1.3 :hostname www.wikipedia.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)
gnutls-negotiate: GnuTLS error: #<process www.wikipedia.org>, -50

Though I am running on Ubuntu 18.04LTS I tried the answer mentioned here hoping it would work, but unfortunately it did not. Please let me know if I need to add something more to my init file, or download some certificate or anything else.

  • You may want to try disabling TLS 1.3; I realize that's for Emacs 26, but it is worth a try...though as the answer says, it's a workaround but not a good one. Nov 12, 2021 at 21:22
  • Thanks for the suggestion. I removed TLS 1.3 from the init file and tried M-x eww and got the following error. error in process filter: eww-display-html: This function requires Emacs to be compiled with libxml2. However, M-x package-refresh-contents works and I was able to install jedi successfully and use it. Even though this is not a solution to make GnuTLS work, it made package-refresh-contents work, so I believe you can write your comment as an answer so that it will help those who face same problem in the future. Thanks again!!
    – Vignesh S
    Nov 13, 2021 at 12:08

1 Answer 1


Not much of an answer but too long for a comment...

Among the various Emacs that I'm using, I use the default emacs-nox package from Ubuntu 18.04 (v25.2.2), and the default emacs-nox package from Ubuntu 21.04 (v27.1). I ​have the following for my package+use-package config. Connections to elpa/melpa, and https websites via eww are working fine for me. This is basically universal to all my Emacs configs.

If it wasn't for your errors with eww I'd have just blamed your issue on elpa being elpa...

Maybe the addition to gnutls-trustfiles ​will make a difference for you?

(require 'package)
(when (>= emacs-major-version 27)
 ​(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3"))
(add-to-list 'package-archives
            ​'("melpa" . "https://melpa.org/packages/") t)

;; Bootstrap 'use-package'
(eval-after-load 'gnutls
 ​'(add-to-list 'gnutls-trustfiles "/etc/ssl/cert.pem"))
(unless (package-installed-p 'use-package)
 ​(package-install 'use-package))
 ​(require 'use-package))
(require 'bind-key)
  • Sorry for the late reply. I could not find "/etc/ssl/cert.pem" on my system. So if you could tell me where I can find that, I will use it and let you know if your suggestion works (and also accept your answer as correct).
    – Vignesh S
    Dec 20, 2021 at 18:24

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.