How to fix apt-key gpg: keyserver receive failed: No dirmngr

Problem:

You want to add a repository signing key using apt-key using a command like

sudo apt-key adv --keyserver hkp://keys.gnupg.net --recv-key E0FF663E

but you get an error message like this:

Executing: /tmp/apt-key-gpghome.qn3065We9J/gpg.1.sh --keyserver hkp://keys.gnupg.net --recv-key E0EE663E
gpg: failed to start the dirmngr '/usr/bin/dirmngr': No such file or directory
gpg: connecting dirmngr at '/tmp/apt-key-gpghome.qn3065We9J/S.dirmngr' failed: No such file or directory
gpg: keyserver receive failed: No dirmngr

Solution

sudo apt install dirmngr

then retry the apt-key command