Skip to content

Instantly share code, notes, and snippets.

@mattrude
Last active July 1, 2024 22:00
Show Gist options
  • Save mattrude/3883a3801613b048d45b to your computer and use it in GitHub Desktop.
Save mattrude/3883a3801613b048d45b to your computer and use it in GitHub Desktop.
GnuPG 2.1.18 Build Instructions for Ubuntu 16.04 LTS

GnuPG 2.1.20 Build Instructions

Below you is my build instructions for GnuPG 2.1.20 released on 03-Apr-2017. These instructions are built for a headless Ubuntu 16.04 LTS server.

Or if you wish, you may use the install script to install GnuPG 2.1.20 by entring the following:

curl -sL "https://gist.github.com/mattrude/3883a3801613b048d45b/raw/install-gnupg2.sh" |sh

Install the needed depends

apt-get -y install libgnutls-dev bzip2 make gettext texinfo gnutls-bin \
build-essential g++

Setup the build

mkdir -p /var/src/gnupg21 && cd /var/src/gnupg21
gpg --list-keys
gpg --recv-keys 0x4F25E3B6 0xE0856959 0x33BD3F06 0x7EFD60D9 0xF7E48EDB

Installing libgpg-error 1.27

wget -c ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.27.tar.gz && \
wget -c ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.27.tar.gz.sig && \
gpg --verify libgpg-error-1.27.tar.gz.sig && tar -xzf libgpg-error-1.27.tar.gz && \
cd libgpg-error-1.27/ && ./configure && make && make install && cd ../

Installing libgcrypt 1.7.6

wget -c ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-1.7.6.tar.gz && \
wget -c ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-1.7.6.tar.gz.sig && \
gpg --verify libgcrypt-1.7.6.tar.gz.sig && tar -xzf libgcrypt-1.7.6.tar.gz && \
cd libgcrypt-1.7.6 && ./configure && make && make install && cd ../

Installing libassuan 2.4.3

wget -c ftp://ftp.gnupg.org/gcrypt/libassuan/libassuan-2.4.3.tar.bz2 && \
wget -c ftp://ftp.gnupg.org/gcrypt/libassuan/libassuan-2.4.3.tar.bz2.sig && \
gpg --verify libassuan-2.4.3.tar.bz2.sig && tar -xjf libassuan-2.4.3.tar.bz2 && \
cd libassuan-2.4.3 && ./configure && make && make install && cd ../

Installing libksba 1.3.5

wget -c  ftp://ftp.gnupg.org/gcrypt/libksba/libksba-1.3.5.tar.bz2 && \
wget -c ftp://ftp.gnupg.org/gcrypt/libksba/libksba-1.3.5.tar.bz2.sig && \
gpg --verify libksba-1.3.5.tar.bz2.sig && tar -xjf libksba-1.3.5.tar.bz2 && \
cd libksba-1.3.5 && ./configure && make && make install && cd ../

Installing npth 1.3

wget -c ftp://ftp.gnupg.org/gcrypt/npth/npth-1.3.tar.bz2 && \
wget -c ftp://ftp.gnupg.org/gcrypt/npth/npth-1.3.tar.bz2.sig && \
gpg --verify npth-1.3.tar.bz2.sig && tar -xjf npth-1.3.tar.bz2 && \
cd npth-1.3 && ./configure && make && make install && cd ../

Install ncurses 6.0

wget -c ftp://ftp.gnu.org/gnu/ncurses/ncurses-6.0.tar.gz && \
wget -c ftp://ftp.gnu.org/gnu/ncurses/ncurses-6.0.tar.gz.sig && \
gpg --verify ncurses-6.0.tar.gz.sig && tar -xzf ncurses-6.0.tar.gz && \
cd ncurses-6.0 && export CPPFLAGS="-P" && ./configure && make && make install && cd ../

Install pinentry 1.0.0

wget -c ftp://ftp.gnupg.org/gcrypt/pinentry/pinentry-1.0.0.tar.bz2 && \
wget -c ftp://ftp.gnupg.org/gcrypt/pinentry/pinentry-1.0.0.tar.bz2.sig && \
gpg --verify pinentry-1.0.0.tar.bz2.sig && tar -xjf pinentry-1.0.0.tar.bz2 && \
cd pinentry-1.0.0 && ./configure --enable-pinentry-curses --disable-pinentry-qt4 && \
make && make install && cd ../

Install GnuPG 2.1.20

wget -c ftp://ftp.gnupg.org/gcrypt/gnupg/gnupg-2.1.20.tar.bz2 && \
wget -c ftp://ftp.gnupg.org/gcrypt/gnupg/gnupg-2.1.20.tar.bz2.sig && \
gpg --verify gnupg-2.1.20.tar.bz2.sig && tar -xjf gnupg-2.1.20.tar.bz2 && \
cd gnupg-2.1.20 && ./configure && make && make install && echo $?

Finishing the build

echo "/usr/local/lib" > /etc/ld.so.conf.d/gpg2.conf && ldconfig -v
#!/bin/bash
apt-get update
apt-get -y install libgnutls-dev bzip2 make gettext texinfo gnutls-bin build-essential g++
mkdir -p /var/src/gnupg21 && cd /var/src/gnupg21
gpg --list-keys
gpg --recv-keys 0x4F25E3B6 0xE0856959 0x33BD3F06 0x7EFD60D9 0xF7E48EDB
wget -c ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.27.tar.gz && \
wget -c ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.27.tar.gz.sig && \
wget -c ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-1.7.6.tar.gz && \
wget -c ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-1.7.6.tar.gz.sig && \
wget -c ftp://ftp.gnupg.org/gcrypt/libassuan/libassuan-2.4.3.tar.bz2 && \
wget -c ftp://ftp.gnupg.org/gcrypt/libassuan/libassuan-2.4.3.tar.bz2.sig && \
wget -c ftp://ftp.gnupg.org/gcrypt/libksba/libksba-1.3.5.tar.bz2 && \
wget -c ftp://ftp.gnupg.org/gcrypt/libksba/libksba-1.3.5.tar.bz2.sig && \
wget -c ftp://ftp.gnupg.org/gcrypt/npth/npth-1.2.tar.bz2 && \
wget -c ftp://ftp.gnupg.org/gcrypt/npth/npth-1.2.tar.bz2.sig && \
wget -c ftp://ftp.gnu.org/gnu/ncurses/ncurses-6.0.tar.gz && \
wget -c ftp://ftp.gnu.org/gnu/ncurses/ncurses-6.0.tar.gz.sig && \
wget -c ftp://ftp.gnupg.org/gcrypt/pinentry/pinentry-0.9.5.tar.bz2 && \
wget -c ftp://ftp.gnupg.org/gcrypt/pinentry/pinentry-0.9.5.tar.bz2.sig && \
wget -c ftp://ftp.gnupg.org/gcrypt/gnupg/gnupg-2.1.20.tar.bz2 && \
wget -c ftp://ftp.gnupg.org/gcrypt/gnupg/gnupg-2.1.20.tar.bz2.sig && \
gpg --verify libgpg-error-1.27.tar.gz.sig && tar -xzf libgpg-error-1.27.tar.gz && \
gpg --verify libgcrypt-1.7.6.tar.gz.sig && tar -xzf libgcrypt-1.7.6.tar.gz && \
gpg --verify libassuan-2.4.3.tar.bz2.sig && tar -xjf libassuan-2.4.3.tar.bz2 && \
gpg --verify libksba-1.3.5.tar.bz2.sig && tar -xjf libksba-1.3.5.tar.bz2 && \
gpg --verify npth-1.2.tar.bz2.sig && tar -xjf npth-1.2.tar.bz2 && \
gpg --verify ncurses-6.0.tar.gz.sig && tar -xzf ncurses-6.0.tar.gz && \
gpg --verify pinentry-0.9.5.tar.bz2.sig && tar -xjf pinentry-0.9.5.tar.bz2 && \
gpg --verify gnupg-2.1.20.tar.bz2.sig && tar -xjf gnupg-2.1.20.tar.bz2 && \
cd libgpg-error-1.27/ && ./configure && make && make install && cd ../ && \
cd libgcrypt-1.7.6 && ./configure && make && make install && cd ../ && \
cd libassuan-2.4.3 && ./configure && make && make install && cd ../ && \
cd libksba-1.3.5 && ./configure && make && make install && cd ../ && \
cd npth-1.2 && ./configure && make && make install && cd ../ && \
cd ncurses-6.0 && ./configure && make && make install && cd ../ && \
cd pinentry-0.9.5 && ./configure --enable-pinentry-curses --disable-pinentry-qt4 && \
make && make install && cd ../ && \
cd gnupg-2.1.20 && ./configure && make && make install && \
echo "/usr/local/lib" > /etc/ld.so.conf.d/gpg2.conf && ldconfig -v && \
echo "Complete!!!"
@jgburet
Copy link

jgburet commented Jul 5, 2017

For later reads, the compiled binary ends at /usr/local/bin/gpg2 on Mint/Ubuntu.
So you just need to

sudo mv /usr/bin/gpg /usr/bin/gpg1
sudo ln -s /usr/local/bin/gpg2 /usr/bin/gpg

I struggled too long to find it 🙈

@racitup
Copy link

racitup commented Oct 17, 2017

On Ubuntu 16.04.3 using revision 47, the curl command failed at building ncurses for the export CPPFLAGS="-P" reason.
The description has been updated but unfortunately not the shell script..
Don't forget to do sudo su first. You paradoxically need gnupg installed, but Ubuntu won't let you uninstall both gnupg and gnupg2 it would seem.
Thanks @mirumu and @mattrude

@jgburet since this script installs gpg2 into /usr/local/bin which is by default before /usr/bin in your PATH, you just need to do the following instead of moving gpg:
sudo ln -s /usr/local/bin/gpg2 /usr/local/bin/gpg

@wuliuxiansheng
Copy link

I think you need to update keys in order to finish installation.

@rasa
Copy link

rasa commented Mar 12, 2018

This works for 2.2.5:

#!/usr/bin/env bash

set -e -x

sudo apt-get update
sudo apt-get -y install libgnutls28-dev bzip2 make gettext texinfo gnutls-bin build-essential g++

mkdir -p gnupg22
pushd gnupg22

wget -c https://gnupg.org/ftp/gcrypt/libgpg-error/libgpg-error-1.27.tar.gz{,.sig}
wget -c https://gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-1.8.2.tar.gz{,.sig}
wget -c https://gnupg.org/ftp/gcrypt/libassuan/libassuan-2.5.1.tar.bz2{,.sig} 
wget -c https://gnupg.org/ftp/gcrypt/libksba/libksba-1.3.5.tar.bz2{,.sig}
wget -c https://gnupg.org/ftp/gcrypt/npth/npth-1.5.tar.bz2{,.sig}
wget -c https://ftp.gnu.org/gnu/ncurses/ncurses-6.1.tar.gz{,.sig}
wget -c https://gnupg.org/ftp/gcrypt/pinentry/pinentry-1.1.0.tar.bz2{,.sig}
wget -c https://gnupg.org/ftp/gcrypt/gnupg/gnupg-2.2.5.tar.bz2{,.sig}

gpg --list-keys
gpg --recv-keys 0x4F25E3B6 0xE0856959 0x33BD3F06 0x7EFD60D9 0xF7E48EDB

for i in *.sig; do
	gpg --verify "$i"
done
for i in *.gz; do
	tar -xzf "$i"
done
for i in *.bz2; do
  tar -xjf "$i"
done
dirs="libgpg-error libgcrypt libassuan libksba npth ncurses pinentry gnupg"
for i in $dirs; do
	CONFIGURE_OPTS=
	if [[ "$i" =~ ^pinentry ]]; then
		CONFIGURE_OPTS="${CONFIGURE_OPTS} --enable-pinentry-curses --disable-pinentry-qt4"
	fi
	pushd $i*/
	./configure $CONFIGURE_OPTS
	make
	sudo make install
	popd
done
sudo tee -a /etc/ld.so.conf.d/gpg2.conf <<<"/usr/local/lib"
sudo ldconfig -v
echo "Complete!!!"
popd

@tuttlem
Copy link

tuttlem commented Oct 18, 2018

Thanks for this!

In order to get ncurses-6.0 to build, I needed the following:

export CPPFLAGS="-P"

@kailash-c
Copy link

kailash-c commented Jul 21, 2021

Thanks for script.
But I face a problem related to supported compression algorithms.

After Installation:

gpg (GnuPG) 2.2.5
libgcrypt 1.8.2
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Supported algorithms:
Pubkey: RSA, ELG, DSA, ECDH, ECDSA, EDDSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
        CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed

I want ZLIB, ZIP, BZIP2 in compression algorithm list.
So Is there any way to support for above compression algorithm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment