When using gpg2 to download a key from a keyserver, it autostarts dirmngr if not running.
If you pass in --homedir <something> to gpg2, gpg2 respects that, but not dirmngr which tries to use the default ~/.gnupg (which may not exist).
Eventually things fail with an IPC connect call failed.
Example:
/usr/local/bin/gpg2 --homedir /Users/mmucklo/somewhere --verbose --keyserver keys.gnupg.net --recv-keys ABCD1233
gpg: no running Dirmngr - starting '/usr/local/bin/dirmngr'
gpg: waiting for the dirmngr to come up ... (5s)
gpg: waiting for the dirmngr to come up ... (4s)
gpg: waiting for the dirmngr to come up ... (3s)
gpg: waiting for the dirmngr to come up ... (2s)
gpg: waiting for the dirmngr to come up ... (1s)
gpg: connecting dirmngr at '/Users/mmucklo/.gnupg/S.dirmngr' failed: IPC connect call failed
gpg: keyserver receive failed: No dirmngr
Can't import key for ABCD1234 from keyserver keys.gnupg.net
Now if you do the following:
mkdir ~/.gnupg; chmod 700 ~/.gnupg
- And rerun the command, it starts to work