How to Remove APT Repository in Linux [4 Easy Methods]

To remove apt repository in Linux, you can use the following methods:

  1. Using the Command Line: Run add-apt-repository --remove <repository_name>.
  2. From Software & Updates: Select Other softwares, select repository, click Remove, and finally click Close.
  3. Editing the sources.list file: Delete the corresponding repository line and save the file.
  4. Using the ppa-purge tool: Run sudo ppa-purge ppa:repository_name/ppa.

Remember to update the system after removing the apt repository to avoid potential system instability and security breaches. It’s also pivotal to keep in mind several difficulties that you can run into while removing the apt repository including the requirement to be an authenticated user, and access write permission to the “sources.list” file, or even installing commands necessary to remove the selected apt repositories with no errors in the background.

This guide discusses an in-depth analysis of 4 methods on how to remove apt repository in Linux. In addition, it discusses 3 common challenges that may occur during the processes with solutions and additional tips.

Process Flow Chart to Remove APT Repository in Linux

[Distro Used Throughout the Tutorial: Ubuntu 22.04]

flow chart to remove apt repository

Watch the Steps to Remove APT Repository in Linux

How to Remove APT Repository in Linux

In Linux, removing apt repositories after task accomplishment is a fundamental operation. Although it is a very straightforward task, there are different methods to remove an apt repository in Linux.

This section mentions 4 effective methods to remove an apt repository including the use of the command line, and the Software & Updates application advocating the GUI-based beginner-friendly approach. Moreover, editing the sources.list file or even utilizing the ppa-purge tool also lets you remove the specific apt repository in Linux.

1. Using the Command Line

The Command Line Interface (CLI) is the most widely used method to remove apt repositories. Adopting this method involves only the use of the simple command apt-add-repository with the –remove option. It provides users with quick and easy solutions without the assistance of the Graphical User Interface (GUI). Follow the steps below to remove apt repository using the Linux command line:

  1. First, open your Ubuntu terminal. You can try, the shortcut: CTRL+ALT+T.
  2. Now, type the following command to list available repositories:
    apt-add-repository --list
    EXPLANATION
    • apt-add-repository: It is used for adding or deleting a repository.
    • –list: An option returning the list of current repositories available to the apt package manager.
  3. After that, press the ENTER button.

    the command showing current apt repositoriesYou should see the list of current repositories on your system like the picture above.

  4. Now, to remove a specific apt repository, type the apt-add-repository command with the --remove flag followed by the repository. For instance, to remove the deb http://archive.getdeb.net/ubuntu wiley-getdeb games repository, run the below command:

    sudo apt-add-repository --remove deb http://archive.getdeb.net/ubuntu wiley-getdeb games
    EXPLANATION
    • sudo: Prefix used to get sudo/root privileges.
    • apt-add-repository –remove: Command deleting the repository.
  5. At this point, type your user account password to access the sudo privileges and press ENTER.

    selected repository is being removed using the apt-add-repository command with remove option

  6. After removing, run the following command to update the system package list:
    sudo apt update
    EXPLANATION
    • sudo: Provides root privileges.
    • apt: Tool for managing packages in the user’s system.
    • update: Updates software packages.

    apt repository list is updated after removal of repository

  7. You can type the following command to verify the changes after removing apt repository:
    apt-add-repository --list

    after updation, the existing repositories are shownHere, you can spot that the system currently doesn’t contain the apt repository namely deb http://archive.getdeb.net/ubuntu wiley-getdeb names.

Note: The apt-add-repository command and the add-apt-repository command both does the same thing. In older Ubuntu versions and some other Debian-based distros, the command was originally called add-apt-repository. Contrarily, apt-add-repository is simply a symlink (symbolic link) to the original expression. They are just 2 different names for the same functionality.

2. Editing the “sources.list” File

The system directory named (/etc/apt/sources.list) handles the management of repositories including the complete package list. So, it is possible to remove a specific apt repository by manually editing the principal apt source configuration file sources.list.

To remove an apt repository by editing the sources.list file, follow the steps below:

  1. Open the terminal and run the following command to back up the contents of the sources.list file to avoid any unwanted alterations:

    sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup
    EXPLANATION
    • cp: Command to copy files.
    • /etc/apt/sources.list: The configuration file to copy.
    • /etc/apt/sources.list_backup: The new file containing file elements as a backup.
  2. making backup file to remove apt repository

  3. Now, type the command mentioned below:
    nano /etc/apt/sources.list
    EXPLANATION
    • nano: Command used to open and edit files in the nano text editor.
    • /etc/apt/sources.list: File to be edited.

    You will see the file open like the following in the text editor where you can see the list repositories:the nano command showing the apt repository urls

  4. Now, locate the repository line to remove and delete it using the backspace button for instance. Below I have removed the repository named deb http://archive.getdeb.net/ubuntu wiley-getdeb games.using backspace to remove apt repository url
  5. After that, press CTRL+S to save the file and press CTRL+X afterward to exit.
  6. You can run the following command to see the updated repository list for verification:
    apt-add-repository --list

    the listing of repositories after removing url from nano text editorSo, you can see that the apt repository named wiley-getdeb games doesn’t exist anymore.

3. Using the “ppa-purge” Tool

The PPA (Personal Package Archive) repository is a subset of the apt repositories providing additional software resources for Debian-based systems like Ubuntu. PPAs are widely used software versions with updated packages not found within the official repositories. This makes removing ppa repositories a common task in APT repository management. For this, you can use the ppa-purge tool to remove the repository and its associated package. Here’s how:

  1. First, run the command ppa-purge followed by the repository name and prefix with sudo. For instance, to remove ppa repository named papirus, run:

    sudo ppa-purge ppa:papirus/papirus
    EXPLANATION
    • ppa-purge: Command line utility to remove ppa and revert installed packages.
    • ppa:papirus/papirus: The ppa to be removed. Here, it’s the papirus ppa that provides icon themes.

    ppa-purge to remove apt repositoryIn the above, the ppa-purge removes the ppa repository named papirus and its associative package files.

  2. Then, run the below command to update the system log after completing the removal:
    sudo apt update

    update system after removing apt repository with ppa-purge

4. Removing from Software & Updates

The Software & Updates application provides a straightforward method to remove apt repository with a user-friendly graphical interface.  Here’s how to remove apt repository via “Software & Updates”:

  1. First, Go to the applications menu, type Software & Updates on the search bar, and click to open the application.typing and then going to software and updates section in settings

  2. Now, select the Other Software tab to see the list of repositories available to the system.now, in other software, the repositories are listed
  3. For deletion, select the repository, then, click on the Remove button and after that click on the Close button to apply changes.repository is being selected, removed and closed
  4. Finally, click on the Reload button to update the repository log.asks to reload for systems' apt repository log updation after removalIn the following snapshot, you can see that only the selected repository has been removed and the remaining ones are shown after updation.via GUI, the current repositories are listed

3 Challenges When Removing “apt” Repositories

Removing apt repositories in Linux offers potential benefits. However, be aware of the following 3 challenges that you might occasionally encounter during the apt repository removal:

1. Write Permission Denied

In method 2, after accessing the file running nano /etc/apt/sources.list command, it might not be possible to remove the apt repositories’ package reference URL due to the wanting of the file writing permission.the source apt repository file is not writtable

Solution 1: To resolve, alter the permission of the sources.list file by running the below command in the terminal:

sudo chmod a+w /etc/apt/sources.list

using mode changing command for writing permission enablingTerminal command to grant all users permission (a+w) to write the file sources.list

NOTE: To know more about file permissions in Linux, read: How to Change File Permissions in Linux with 6 Examples

Solution 2: Prefix with sudo to open the sources.list file using the nano text editor with superuser privileges, directly allowing you to make changes:

sudo nano /etc/apt/sources.list

2. “ppa-purge: command not found”

In using method-3 (ppa-purge tool), the system might return an error like the following snapshot in case the ppa-purge tool is not installed in the system:ppa-purge command not found The system threw an error ppa-purge: command not found since it does not have the ppa-purge tool installed.

Solution: Type the following command in the terminal and press ENTER:

sudo apt install ppa-purge

Upon running the command, the system will install the ppa-purge tool like the following:installing ppa-purge to remove apt repository Finally, you are good to remove the ppa repository using the “ppa-purge” command.

3. Authentication Required

In method 4, using Software&Updates, to remove an apt repository may result in the need to avail superuser privileges to successfully remove the apt repository. In this case, the system displays an authentication requirement alert like the following:authentication needed to remove apt repositoryAfter clicking the Remove button, you will get an alert saying Authentication Required like the aforementioned snapshot.

Solution: provide the user account password for authentication to smoothly remove the selected “apt” repository.

5 Tips to Avoid Errors When Removing “apt” Repository

Here are some additional tips to fix errors while removing apt repositories in Linux:

  1. Maintain Backup File: Make sure to keep the backup of the file system before making any changes to the sources.list file. Cross-check after removing apt repository via manual editing. This is because a small accidental error while editing might result in a vulnerable system.
  2. Don’t Remove Essential Repositories: Be careful not to remove any repositories essential for the operating system since it may cause unstable system security and the package management may become restive. So, it’s recommended to verify the magnitude of the repository before deletion.
  3. Keep Repository in place: If unsure to remove, it is best to leave that repository in place.
  4. Update the System: Always update the system using the sudo apt update command after the removal of an apt repository. This is a necessary step to avoid unwanted errors like system instability, software vulnerabilities, missing relevant packages, etc.
  5. Beware of Dependency Issues: Occasionally, you may encounter issues with package dependency after removing the ppa repository using ppa-purge tool or any other. Since the solution to this problem can introduce intricate situations at times, it’s wise to verify whether the ppa removal causes dependency conflicts before actual execution.

Conclusion

In this feature, I have discussed 4 methods to remove apt repository in Ubuntu with multiple examples. I have also walked you through 3 different challenges with effective solutions along with some standard tips and tricks for the seamless removal of apt repositories in Linux. Using these methods, you can easily remove the repository from the system you no longer require. I hope this article aids your learning of repository management and takes you one step further in becoming a Linux power user.

Frequently Asked Questions

How do I remove an apt repository?

Run the apt-add-repository command with the –remove option on the prompt followed by the repository name or URL to remove the selected apt repository from your system. For instance, to remove a repository named Skype, you will run the command apt-add-repository --remove Skype.

What is the difference between an apt repository and a ppa repository in Ubuntu?

An apt (advanced package tool) repository in Ubuntu is the primary source for software package utilities officially maintained and supported by Canonical which is stable, and secure. On the other hand, the ppa (personal package archive) repository is a convenient way to install, and update packages that are not available in the official repositories. PPAs often contain customized versions of software. However, it may also become outdated and introduce security risks.

Can I remove a ppa repository in Linux?

Absolutely. To remove a ppa repository in Linux, you can use the command sudo  apt-add-repository –remove ppa: repository name/ppa. For instance, to remove the ppa repository graphics-drivers, run this command:

sudo apt-add-repository --remove ppa:graphics-drivers/ppa

Is it possible to undo the changes made to the sources.list file?

Yes, it’s possible. To undo the changes made to the sources.list file, first you must create a backup file. For example, you make a copy of the file using the command sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup. So, if you encounter any unwanted issues after removing apt repositories, you can easily restore from the backup file by running the command:  sudo cp  /etc/apt/sources.list_backup /etc/apt/sources.list. However, make sure to update the system package list using the sudo apt update command to reflect the changes.

Are there any alternative ways to remove apt repositories other than the command line?

Yes, additionally, you can remove any “apt” repository using  GUI (Graphical User Interface):

  1. Go to Other Software from Software & Updates.
  2. Select the intended repository and click Remove.

Provide your user account password if the system asks for it to refresh the package cache.

How to list all the apt repositories in Linux?

To list all the available apt repositories on your system:

  1. Go to the terminal and run this command: apt-add-repository --list
  2. Go to the Other Software from Software and Updates to see the list of all the apt repositories.
  3. Run the nano /etc/apt/sources.list command on the prompt and scroll down to the end of the file sources.list.

Is it safe to remove all the apt repositories?

No, removing all of your systems’ “apt” repositories is unsafe. Some repositories are essential for the smooth operation of your system and if you remove repositories as such, you may not be able to update or install the package in the future. As a result, these software packages will become out of date and the system will be susceptible to potential security threats. To resolve this, find alternative repositories to ensure the continuation of timely updates.

Should I Update after removing apt repositories?

Yes, you should update the system just after you remove apt repositories. This is due to making the system aware of the recent manipulation in the repository list and fetching the latest information.

To update, run the command sudo apt update and enter the user password for root user privileges.

Related Articles


<< Go Back to Repository Configuration in Linux | Package Management in Linux | Learn Linux Basics

5/5 - (6 votes)
Md Masrur Ul Alam

Assalamu Alaikum, I’m Md Masrur Ul Alam, currently working as a Linux OS Content Developer Executive at SOFTEKO. I completed my Bachelor's degree in Electronics and Communication Engineering (ECE)from Khulna University of Engineering & Technology (KUET). With an inquisitive mind, I have always had a keen eye for Science and Technolgy based research and education. I strongly hope this entity leverages the success of my effort in developing engaging yet seasoned content on Linux and contributing to the wealth of technical knowledge. Read Full Bio

2 thoughts on “How to Remove APT Repository in Linux [4 Easy Methods]”

    • Thank you so much for your feedback. I greatly appreciate and your thoughtful positive comments will keep me motivated to deliver more useful articles. For further meeting the needs of your queries, check out the other articles.

      Reply

Leave a Comment