How To Install python-gpg on Ubuntu 18.04

In this tutorial we learn how to install python-gpg on Ubuntu 18.04. python-gpg is Python interface to the GPGME GnuPG encryption library (Python 2)

Introduction

In this tutorial we learn how to install python-gpg on Ubuntu 18.04.

What is python-gpg

python-gpg is:

The “gpg” Python module is, for the most part, a direct interface to the C GPGME library. However, it is re-packaged in a more Pythonic way – object-oriented with classes and modules. Take a look at the classes defined here – they correspond directly to certain object types in GPGME for C.

Features:

  • Feature-rich, full implementation of the GPGME library. Supports all GPGME features except interactive editing (coming soon). Callback functions may be written in pure Python.
  • Ability to sign, encrypt, decrypt, and verify data.
  • Ability to list keys, export and import keys, and manage the keyring.
  • Fully object-oriented with convenient classes and modules.

This is the official upstream Python 2 binding for GPGME.

There are three methods to install python-gpg on Ubuntu 18.04. We can use apt-get, apt and aptitude. In the following sections we will describe each method. You can choose one of them.

Install python-gpg Using apt-get

Update apt database with apt-get using the following command.

sudo apt-get update

After updating apt database, We can install python-gpg using apt-get by running the following command:

sudo apt-get -y install python-gpg

Install python-gpg Using apt

Update apt database with apt using the following command.

sudo apt update

After updating apt database, We can install python-gpg using apt by running the following command:

sudo apt -y install python-gpg

Install python-gpg Using aptitude

If you want to follow this method, you might need to install aptitude first since aptitude is usually not installed by default on Ubuntu. Update apt database with aptitude using the following command.

sudo aptitude update

After updating apt database, We can install python-gpg using aptitude by running the following command:

sudo aptitude -y install python-gpg

How To Uninstall python-gpg on Ubuntu 18.04

To uninstall only the python-gpg package we can use the following command:

sudo apt-get remove python-gpg

Uninstall python-gpg And Its Dependencies

To uninstall python-gpg and its dependencies that are no longer needed by Ubuntu 18.04, we can use the command below:

sudo apt-get -y autoremove python-gpg

Remove python-gpg Configurations and Data

To remove python-gpg configuration and data from Ubuntu 18.04 we can use the following command:

sudo apt-get -y purge python-gpg

Remove python-gpg configuration, data, and all of its dependencies

We can use the following command to remove python-gpg configurations, data and all of its dependencies, we can use the following command:

sudo apt-get -y autoremove --purge python-gpg

References

Summary

In this tutorial we learn how to install python-gpg package on Ubuntu 18.04 using different package management tools: apt, apt-get and aptitude.