How to Remove Software Repositories on Ubuntu
The ability to add repositories on Linux is essential to get software from third-party sources other than the official repos. On Ubuntu, you can add a repository using the add-apt-repository command or by editing the sources.list file.
But how do you remove the added repository once you’re done with it? Deleting a repository entry on Ubuntu is even easier than adding one, and there are multiple ways to do the same.
Deleting the Repository Entry From sources.list
The most convenient way to remove an unwanted package repository on Ubuntu is by editing the sources.list file. The sources file lists all the configured repositories on your system. You can view the contents of the file using any of the file-viewing Linux programs.
Start by opening the file with a text editor of your choice (for this guide, we’ll use Vim):
sudo vim /etc/apt/sources.list
Find the repository you want to remove and delete the entire line. Save the file and exit Vim to proceed. Now, update the package sources with:
sudo apt update
After removing a repository from the sources.list file, you won’t receive any package updates from it.
The sources.list file is a root-owned file and it can break repository configuration if not modified properly.
Removing the GPG Key for the Repository
Packages in a repository are signed with a pair of keys: public and private. When you add a repository, you ask the package manager (APT) to trust the packages found in that repo. After deleting the repository entry from your sources file, you should also delete the GPG key associated with it.
To do so, first, list all the trusted keys with:
sudo apt-key list
The second line in the pub entry is the actual key, while uid is the repository name. Find the repository you just deleted, then copy the last eight characters of its key.
Enter the following to remove the key, replacing the hex value at the end with the characters you copied:
sudo apt-key del D38B4796
You can also specify the entire key in the command if you want:
sudo apt-key del "EB4C 1BFD 4F04 2F6D DDCC EC91 7721 F63B D38B 4796"
Remove a PPA Using add-apt-repository
When it comes to removing a PPA, the best—and safest—way is to use add-apt-repository. It’s the only command you need to add as well as remove PPAs on Ubuntu. Don’t let its name fool you into thinking otherwise.
Get a list of all configured PPAs by listing the contents of the /etc/apt/sources.list.d directory using the ls command:
Once you’ve found the PPA you want to remove, use the -r flag with add-apt-repository:
sudo add-apt-repository -r ppa:author/reponame
If the output displays the “add-apt-repository: command not found” error, you’ll have to install the tool first.
You can also delete the PPA folder from the sources.list.d directory and it’ll remove the repository from your system.
Use the Ubuntu Software Updater to Remove a Repository
Ubuntu offers a graphical way to manage software repositories and third-party PPAs using the Software Updater app. To begin, launch Software Updater from the applications menu and click Settings.
Once launched, switch to the Other Software tab. You’ll see a list of all the third-party software sources configured on your computer. To disable a repository, uncheck the box corresponding to the repo and enter the administrator password.
If you’ve decided to remove the package repository, highlight the entry and click Remove.
Finally, update the package sources using APT:
sudo apt update
You can also edit or add a third-party repository on Ubuntu using the Software Updater app.
Software Management on Ubuntu Made Easy
Adding and deleting repositories is another aspect of package management on Ubuntu and other Linux distros. To maintain your system security, you should always check if a repository or PPA is genuine, and doesn’t offer any malicious software.
Ubuntu comes with a few repositories preconfigured. These are the official repositories from where you can download trusted packages to install.