Macos – Use gpg2 as gpg replacement OSX


I installed the gnupg2 formula from Homebrew successfully and can run gpg2 from the command line. However, certain programs such as git expect to run gpg rather than gpg2.

I resolved this problem by using what I feel like is a dirty hack: a symlink of gpg2 to gpg:

ln -s /usr/local/bin/gpg2 /usr/local/bin/gpg

Is there a more proper way to do this? Should I just settle for installing the gnupg formula?

Sort of looking for something like this for OSX: How to set gpg2 as default implementation of gpg on debian?.

Best Answer

Be aware that GnuPG 2 sometimes has slightly different ouput, especially with GnuPG 2.1. This will usually not be a problem, but in rare cases weird things might happen.

Individually configure the gpg binary to be used per application. For example, git has the gpg.program option. From man gpg-config:


Use this custom program instead of "gpg" found on $PATH when making or verifying
a PGP signature. The program must support the same command-line interface as
GPG, namely, to verify a detached signature, "gpg --verify $file - <$signature"
is run, and the program is expected to signal a good signature by exiting with
code 0, and to generate an ascii-armored detached signature, the standard input
of "gpg -bsau $key" is fed with the contents to be signed, and the program is
expected to send the result to its standard output.

Use git config --global gpg.program gpg2 to choose GnuPG 2 for your user, or replace --global with --system to change the setting for all users.