remove apt repository

The add-apt-repository script adds an apt repository to /etc/apt/sources.list or a file in the /etc/apt/sources.list.d/ directory in the case of PPAs. You can manually add external repos to your sources list too.  

Removing packages is very simple, but what about removing such apt repositories? Actually, that’s pretty simple too. There are multiple ways to go about this, from using the same add-apt-repository script, to manually deleting the files and entries.

Remove Repo from Software & Updates

If you’re new to Ubuntu, you may prefer performing tasks graphically. To remove apt repositories specifically, search and open Software & Updates.

In the Other Software tab, select the repo and press Remove. It’s that easy.

Do keep in mind that this only removes the repositories. You must uninstall the packages separately.

Using add-apt-repository

The add-apt-repository script supports the remove flag for removing the specified repositories. You can use this method to easily remove PPAs.

sudo add-apt-repository --remove ppa:PPA-Name/ppa

Simply replace PPA-Name with the actual name like so

sudo add-apt-repository --remove ppa:mozillateam/ppa

Remove Repo Source Manually

If you manually created a sources entry or file to add a repo, you’ll also need to manually delete them.

To remove entries from the sources list, open it with a text editor.

sudo nano /etc/apt/sources.list

Comment out or remove the repos you no longer need, save the changes, and exit the editor.

Similarly, to remove PPAs and manually added repos, list the contents of the sources.list.d directory.

ls /etc/apt/sources.list.d

Now, delete the appropriate .list or .sources file to remove the repository.

sudo rm /etc/apt/sources.list.d/google-chrome.list

Deleting GPG Keys

External apt repositories are usually signed with GPG keys to verify that the packages can be trusted. These keys are stored in the /etc/apt/trusted.gpg.d/ directory. After removing the repos, you need to remove the keys separately.

If you added the keys with apt-key, you can use the same utility to remove the keys as well. First, list the trusted keys and note the key ID of the relevant repo.

sudo apt-key list

Then, enter the last 8 characters of the key to delete it like so

sudo apt-key del D38B4796

Alternatively, if you added the GPG keys manually, you should delete them manually as well like so

sudo rm /etc/apt/trusted.gpg.d/google-chrome.gpg
Anup Thapa

Senior Writer

Anup Thapa is a Linux enthusiast with an extensive background in computer hardware and networking. His goal is to effectively communicate technical concepts in a simplified form understandable by new Linux users. To this end, he mainly writes beginner-friendly tutorials and troubleshooting guides. Outside of work, he enjoys reading up on a range of topics, traveling, working out, and MOBAs.