Gpg: keyserver receive failed: No keyserver available error and solution

I run the following on Linux (Ubuntu to be specific)

/usr/bin/gpg --homedir /home/tom/.my_app/.gnupg --no-permission-warning --keyserver pgp.mit.edu --recv-keys my_key_here

but getting the following message:
gpg: keyserver receive failed: No keyserver available

How do I fix this one?

The procedure to fix “gpg: keyserver receive failed: No keyserver available” is as follows:

  1. Open terminal app on your Linux machine.
  2. Run the following pkill command to kill dirmngr that takes care of accessing the OpenPGP keyservers:
sudo pkill dirmngr
  1. Try again gpg command again:
/usr/bin/gpg --homedir /home/tom/.my_app/.gnupg --no-permission-warning --keyserver pgp.mit.edu --recv-keys my_key_here
  1. If above failed try prefixing the hkp:// to pgp.mit.edu. Example:
/usr/bin/gpg --homedir /home/tom/.my_app/.gnupg --no-permission-warning --keyserver hkp://pgp.mit.edu --recv-keys my_key_here
  1. Here is how to debug dirmngr issues:
sudo pkill dirmngr; dirmngr --debug-all --daemon --standard-resolver