Compile your own GPG

by Volker Diels-Grabsch

How to compile your own GPG locally.

Created 2017-09-13, Last updated 2017-09-13
Articles

Caution!

This is a short recipe to compile your own GPG locally, that is, in your home directory without any system-wide install. Why? Sometimes you want GPG-2, but the system provides only the old GPG-1. Note that you, the future reader, should not use the versions mentioned here, but the latest versions of all packages. And that you should verify the integrity of all downloaded sources. Also, you need to rebuild everything as soon as there are updates to the libraries, especially security updates.

In other words, you should use a proper package manager instead. But if for some reason you really want (or need) to build GPG on your own, this is how to do it.

Build

Create a new, empty directory and change into it:

mkdir my_gpg_build
cd my_gpg_build

Decide which target directory you want, and save it into the variable prefix. Note that this must be an absolute path, so if you want to put everything into the dest sub directory, you need to prepend the current absolute path to it:

prefix=`pwd`/dest

Download all needed sources:

wget https://gnupg.org/ftp/gcrypt/npth/npth-1.5.tar.bz2
wget https://gnupg.org/ftp/gcrypt/libgpg-error/libgpg-error-1.27.tar.bz2
wget https://gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-1.8.1.tar.bz2
wget https://gnupg.org/ftp/gcrypt/libksba/libksba-1.3.5.tar.bz2
wget https://gnupg.org/ftp/gcrypt/libassuan/libassuan-2.4.3.tar.bz2
wget https://gnupg.org/ftp/gcrypt/gnupg/gnupg-2.2.0.tar.bz2

Verify the integrity of all downloaded sources.

Build everything:

tar xf npth-*.tar.bz2
(
  cd npth-*
  ./configure --prefix=$prefix
  make -j 4
  make install
)
tar xf libgpg-error-*.tar.bz2
(
  cd libgpg-error-*
  ./configure --prefix=$prefix
  make -j 4
  make install
)
tar xf libgcrypt-*.tar.bz2
(
  cd libgcrypt-*
  ./configure --prefix=$prefix --with-libgpg-error-prefix=$prefix
  make -j 4
  make install
)
tar xf libksba-*.tar.bz2
(
  cd libksba-*
  ./configure --prefix=$prefix --with-libgpg-error-prefix=$prefix
  make -j 4
  make install
)
tar xf libassuan-*.tar.bz2
(
  cd libassuan-*
  ./configure --prefix=$prefix --with-libgpg-error-prefix=$prefix
  make -j 4
  make install
)
tar xf gnupg-*.tar.bz2
(
  cd gnupg-*
  ./configure \
    --prefix=$prefix \
    --with-npth-prefix=$prefix \
    --with-libgpg-error-prefix=$prefix \
    --with-libgcrypt-prefix=$prefix \
    --with-libassuan-prefix=$prefix \
    --with-ksba-prefix=$prefix \
    LDFLAGS="-Wl,--rpath=$prefix/lib" \
  ;
  make -j 4
  make install
)

Check that the final gpg tool exists and points to our self-built libraries rather than the system libraries:

ldd $prefix/bin/gpg

Verify that the gpg tool actually runs:

$prefix/bin/gpg --version

Have fun with your new gpg binary!