Ubuntu comes with four official repositories “Main”, “Restricted”, “Multiverse”, and “Universe”. Apart from these repositories, the user can also add external software repositories for downloading and installing software applications.
Besides these repositories, the “GPG” keys are also added to secure the data. It’s recommended to delete the software repositories along with the GPG keys to clean up the system cache.
This guide lists down the possible method to delete a repository alongside its GPG key in Ubuntu with the following guidelines:
- How To Delete a Repository in Ubuntu?
- Delete an “apt” Repository in Ubuntu
- Delete a “PPA” Repository Using “apt”
- Delete a “PPA” Repository Using “PPA Purge”
- How To Delete a GPG Key in Ubuntu?
- Delete the Private “GPG” Key
- Delete the Public “GPG” Key
How To Delete A Repository in Ubuntu?
The software repositories i.e “apt” and “PPA” can be easily deleted through the “add-apt” package manager that is associated directly with the “Ubuntu Software” center.
Delete an “apt” Repository in Ubuntu
An “APT” repository refers to a set of deb packages that allow the users to update, install, remove, and upgrade the software packages using “apt” tools.
It is generally stored in the “/etc/apt/sources.list” file by default. Open the “/etc/apt/sources.list” file in the Ubuntu default text editor i.e “nano”:
$ sudo nano /etc/apt/sources.list
When the file is opened, find the desired “apt” repository and delete it. In this scenario we deleted the highlighted “mongodb.org” apt repo as shown below:
Delete a “PPA” Repository Using “apt”
If the user added the “PPA” repository then it can be deleted using “apt”. It will only delete the “PPA” repository from a system, not its installed packages.
Use the “-r(remove)” flag with the “add-apt” command to delete the “shutter/ppa” from the system in this way:
$ sudo add-apt-repository -r ppa:shutter/ppa
The “shutter/ppa” repository has been removed.
Delete a “PPA” Repository Using “PPA Purge”
To completely delete the “PPA” repository use the “PPA Purge” command line tool that completely removes/deletes a PPA and its all packages from the “sources.list.d” directory.
It is an external utility so first, install it in Ubuntu using the default “apt” package manager:
$ sudo apt install ppa-purge
The “ppa-purge” tool is successfully installed.
Execute the “ppa-purge” with the superuser privileges i.e “sudo” to completely delete the “ppa” from ubuntu:
$ sudo ppa-purge <PPA-Name>
The “shutter/ppa” repository has been completely deleted from the Ubuntu system.
Lastly, update the “/etc/apt/sources.list” to save the changes:
$ sudo apt update
How To Delete GPG Key in Ubuntu?
Ubuntu generally uses the “apt-key” tool to add the repository key after installing a repository. It is needed for security purposes. Most of the time it generates an error “apt-key is deprecated”.
To get rid of this problem both internal and third-party repositories use the “GPG” key or “GnuPG”. It offers “public” and “private” keys to encrypt and decrypt the data or messages. This section tells how to delete them in ubuntu when they are created.
Delete the Private “GPG” Key
The “Private GPG” key is generally known as a “secret” key that can be listed down using the “GPG” command with the “–list-secret-keys” flag:
$ gpg --list-secret-keys
All the private/secret gpg keys are displayed in the terminal.
From these we will delete the highlighted key of specific user “annajohnson” using the “–delete” flag with the “GPG” command:
$ gpg --delete-secret-key annajohnson
The user “annajohnson” private gpg key denoted by “sec” keyword has been deleted.
Delete the Public “GPG” Key
The “Public GPG” key is useful for the encryption of data. It follows the same syntax for the deletion as the “Private GPG” key.
In this section, we will delete the “Public GPG” key of the “annajohnson” user using the “GPG” command followed by the “–delete-key” flag:
$ gpg --delete-key annajohnson
The user “annajohnson” public gpg key denoted by “pub” keyword has been deleted.
In Ubuntu use the “add-apt” command line tool to delete the repository and the “gpg” to delete the “GPG” keys i.e “public” and “private”. The Debian “apt” and “ppa” repositories are stored in the “/etc/apt/sources.list” file. This guide has illustrated the possible aspects to delete a repository and GPG key in Ubuntu.