How To Remove APT Repository In Ubuntu [4 Best Methods]

Written by

Reviewed by

Last updated: May 9, 2024

Expert verified

SVG Image


To remove apt repository in Ubuntu, you can try the following method:

  1. Start by backing up the sources.list file: sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup.
  2. Open the sources.list file with superuser privileges in a text editor, such as Nano, by typing: sudo nano /etc/apt/sources.list.
  3. Locate and delete the lines related to the repository you wish to remove.
  4. Save the changes (in Nano, press Ctrl + O and then Ctrl + X to exit).
  5. Apply the changes by updating the package list: sudo apt update.

Read the guide below to learn different ways to remove apt repository in Ubuntu and the common errors with possible solutions.

If you’re exploring Ubuntu, managing APT repositories is crucial for keeping your system efficient and secure. Sometimes, these repositories become outdated or unnecessary, posing security risks and slowing down your updates. In this guide, I’ll walk you through various methods to remove APT repositories in Ubuntu. This will help enhance your system’s security and performance. You’ll find easy-to-follow instructions tailored for both new and experienced users. I’ll also share tips to avoid common mistakes that could disrupt your system’s functionality. Let’s simplify and secure your Ubuntu setup together!

What is an APT Repository, and Why Should You Remove It?

An APT (Advanced Package Tool) repository is a collection of packages (software, applications, and system utilities) maintained on a server, from which users can install and update software on Debian-based systems like Ubuntu. These repositories are critical components that help manage software installations and ensure you have the latest updates for security and functionality.

There are several reasons why you might need to remove an APT repository:

  1. Security Concerns: If a repository is not maintained or has become compromised, it could distribute outdated or malicious software packages.
  2. Software Compatibility: Some repositories might provide packages that conflict with others or destabilize your system due to compatibility issues.
  3. Clean Up: Removing unused or unnecessary repositories can simplify system management and speed up the update process by reducing the number of sources your system checks for updates.
  4. System Performance: Some third-party repositories may slow down the package management process or introduce unstable or beta versions of software that might affect system performance.

How to Remove APT Repository Ubuntu?

To remove an APT repository in Ubuntu, you can use several straightforward methods. For command line enthusiasts, use sudo add-apt-repository --remove ppa:repository_name to specify the repository you wish to remove. Confirm the removal by updating the package list with sudo apt update.

Alternatively, for a GUI approach, press the Super key, type, and open Software & Updates. Go to the Other Software tab, uncheck the repository you want to remove, and click Close. Ubuntu will automatically update the package list. Eliminating unused or risky repositories ensures your system remains optimized.

That was the quick answer. To learn four different methods to remove apt repository in Ubuntu, keep reading the article below:

1. Using the Command Line

The command-line method offers precise control over managing APT repositories in Ubuntu. This method is ideal for experienced users who prefer a quick and efficient way to handle repositories without the need for graphical interfaces. Follow these steps to remove apt repository in Ubuntu using command-line:

  1. Open the Terminal by pressing Ctrl + Alt + T.
opening terminal 5
  1. To list all the repositories currently added to your system, run the following command:
sudo apt update
  1. This command updates the package lists and fetches information about available packages from the repositories.
apt remove repository
  1. To remove a specific repository, use the add-apt-repository command with the --remove option. For example, to remove a PPA repository, you would run:
sudo add-apt-repository --remove ppa:repository_name
  1. This command removes the specified repository from the sources.list file.
removing desired repository
  1. Press Enter to confirm the removal of the repository:
confirm the removing of repository
  1. After removing the repository, update the package list again:
sudo apt update
  1. This command updates the package lists to reflect the changes made in the previous step.
ubuntu remove apt repository

2. Removing via Software & Updates

For users who prefer a more user-friendly approach, the Software & Updates graphical interface provides a straightforward way to manage repositories. This method is perfect for beginners or those who are more comfortable with a visually intuitive environment. Here is how to do it:

  1. Press the Super key (Windows key) to open the Activities Overview.
pressing keys to open activities overview
  1. Type Software & Updates in the search bar and click on the application to open it.
opening software updates application
  1. In the Other Software tab, you will find a list of repositories added to your system.
list of repositories
  1. Uncheck the repositories you wish to remove.
uncheck repositories to remove them
  1. Click Close to apply the changes. Ubuntu will update the package list automatically.
linux remove repository from apt

    3. Editing sources.List File

    Editing the sources.list file directly gives you precise control over your repository configuration. It is best suited for users who want to customize their repositories extensively or need to handle complex repository setups. Follow this step-by-step guide to remove apt repository in Ubuntu by editing sources.list file:

    1. Open the Terminal and create a backup of the sources.list file to avoid any accidental changes:
    sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup
    1. This command creates a copy of the original sources.list file and save it as sources.list_backup, ensuring you have a backup in case of errors.
    creating a backup file
    1. Open the sources.list file in a text editor (e.g., Nano, Vim, or Gedit) with superuser privileges:
    sudo nano /etc/apt/sources.list
    1. This command opens the sources.list file in the Nano text editor with superuser permissions, allowing you to make changes.
    opening sources.list file in nano editor
    1. Locate the lines corresponding to the repository you want to remove and delete them.
    2. Save the changes by pressing Ctrl + O, then exit the editor by pressing Ctrl + X.
    removing lines related to repository from sources.list file
    1. Update the package list to apply the changes:
    sudo apt update
    1. This command updates the package lists to reflect the changes made in the sources.list file.
    ubuntu apt remove repository

    4. Using the ppa-purge Tool

    The ppa-purge tool is designed specifically for removing PPAs and their associated packages from your system. It is a powerful and efficient way to revert your system to its default state, ensuring optimal stability. Here is how to do it:

    1. Install ppa-purge if you haven’t already:
    sudo apt install ppa-purge
    1. This command installs the ppa-purge tool, which allows you to remove PPAs and their associated packages.
    installing ppa purge tool
    1. Identify the PPA repository you want to remove. You can find it by checking the list of repositories using the command:
    sudo apt update
    1. This command updates the package lists and fetches information about available packages from the repositories.
    checking list of repositories
    1. Use ppa-purge to remove the specific PPA along with its associated packages. For example, if the PPA is named repository_name:
    sudo ppa-purge ppa:repository_name
    1. This command runs ppa-purge with the specified PPA name as an argument, initiating the removal process.
    removing repository using ppa purge tool
    1. Update the package list after the removal is complete:
    sudo apt update
    1. This command updates the package lists to reflect the changes made by removing the PPA.
    update the package list after the removal

    Advanced Method: Removing the GPG Key of the  APT Repository

    Removing an APT repository and its GPG keys from your Ubuntu system helps maintain its security by preventing the installation of unauthenticated packages. This brief guide will show you how to safely remove the keys associated with the repository, ensuring your system remains secure and efficient:

    1. Before you can remove a repository, you need to know the GPG key associated with it, as this will help you identify which repository to remove. List all the GPG keys stored in your APT keyring by running:
    sudo apt-key list

    Look through the list for the key associated with the repository you want to remove. Key listings will typically include an identifier (often an email) or a description that can help you identify which key belongs to which repository.

    listing gpg keys in ubuntu
    1. Once you’ve identified the key associated with the repository you wish to remove, you can delete it. Remove the key using its ID (replace key_id with the actual ID from the apt-key list output):
    sudo apt-key del key_id
    deleting gpg key in ubuntu

    5 Common Errors When Removing APT Repository in Ubuntu

    When managing APT repositories in Ubuntu, it’s essential to exercise caution to avoid potential errors. You can maintain a stable and secure Ubuntu system without facing unnecessary issues by being aware of these common errors and following best practices for managing APT repositories. Here are five common errors that you may encounter:

    • 🚫 Accidentally Removing Essential Repositories: One of the most common mistakes is inadvertently removing essential repositories that are necessary for system updates and package installations. This can lead to missing software packages, security vulnerabilities, and a broken package management system. Always double-check the repository’s significance before removing it.
    • 🔄 Failure to Update Package Lists After Removal: After removing a repository, many users forget to update the package lists. This results in outdated information in the APT database, causing errors during software installation or updates. Remember to run sudo apt update after any changes to your repositories.
    • 📥 Leaving Orphaned Packages on the System: Removing a repository may leave behind orphaned packages—software installed from the removed repository but no longer supported. Orphaned packages can cause conflicts and lead to a less stable system. Use tools like deborphan to identify and remove these lingering packages.
    • 🔧 Incorrectly Editing the sources.list File: Manually editing the sources.list file can be tricky, and even a small typo can render your package management system unusable. Be cautious when using text editors in the Terminal, and always create a backup before making any changes. Double-check your edits for accuracy.
    • ⚙️ Dependencies Issues After Removing a PPA: When using ppa-purge or other PPA removal methods, you might encounter dependency problems, especially if the removed PPA provided critical dependencies for other packages. Resolving these issues can be complex and time-consuming. Before removing a PPA, ensure that it won’t cause significant dependency conflicts.

    Ubuntu: Remove Repository from APT

    In this article, I’ve discussed various methods to remove APT repository in Ubuntu, including using the command line, Software & Updates, editing the sources.list file, and employing the ppa-purge tool. While these methods empower you to declutter your system and enhance security, it’s essential to be cautious of common errors like accidentally removing essential repositories and encountering dependency issues.

    For further learning, consider exploring articles on Ubuntu package management best practices, understanding the role of PPAs in software installation, and optimizing system performance through repository maintenance. Expanding your knowledge in these areas will make you a proficient Ubuntu user, enabling you to unleash the full potential of this versatile operating system.

    Frequently Asked Questions

    Can I remove all repositories except the default ones?

    Yes, you can remove additional repositories that you may have added while retaining the default ones that come with Ubuntu. However, exercise caution when removing repositories, as some may contain essential packages required for system functionality. To identify non-essential repositories, review their purpose and whether they are still actively maintained. It’s recommended to keep the default repositories and remove only those that you are certain are unnecessary for your specific needs.

    To check for broken repository links and resolve any related dependency issues, you can use the apt-get command with the --fix-broken option. Open the Terminal and run the following command: sudo apt-get --fix-broken install. This command attempts to repair any broken dependencies in your repositories, ensuring that your software installation and update processes can proceed smoothly. If any missing or broken packages are found, apt-get will try to resolve them automatically, allowing you to maintain a well-functioning system.

    What happens if I remove a repository that contains installed packages?

    When you remove a repository that contains installed packages, those packages will no longer receive updates from the removed repository. However, the packages will remain installed on your system. As a result, these packages will become stagnant, potentially leading to outdated software with unpatched security vulnerabilities over time. To mitigate this issue, consider finding alternative repositories or official sources for the packages you need, ensuring they continue to receive timely updates for enhanced security and performance.

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

    Yes, you can revert changes made to the sources.list file if you have previously created a backup of the original file. Before editing the sources.list file, make a copy of it with the following command: sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup. Should you encounter any issues after making changes to the file, you can restore it from the backup by running: sudo cp /etc/apt/sources.list_backup /etc/apt/sources.list. After restoring the original file, remember to update the package list by running sudo apt update to reflect the changes correctly.

    Can I delete repositories without an internet connection?

    No, removing repositories requires an active internet connection. When you remove a repository, you need to update the package list to reflect the changes and ensure that your system correctly accesses available software sources. Without an internet connection, you won’t be able to access the necessary repositories, potentially leading to errors during the package management process. If you have a limited or unstable internet connection, consider disabling the unwanted repositories temporarily instead of removing them completely, as this can be done without requiring internet access.



    Ojash is a skilled Linux expert and tech writer with over a decade of experience. He has extensive knowledge of Linux's file system, command-line interface, and software installations. Ojash is also an expert in shell scripting and automation, with experience in Bash, Python, and Perl. He has published numerous articles on Linux in various online publications, making him a valuable resource for both seasoned Linux users and beginners. Ojash is also an active member of the Linux community and participates in Linux forums.



    Akshat is a software engineer, product designer and the co-founder of Scrutify. He's an experienced Linux professional and the senior editor of this blog. He is also an open-source contributor to many projects on Github and has written several technical guides on Linux. Apart from that, he’s also actively sharing his ideas and tutorials on Medium and Attirer. As the editor of this blog, Akshat brings his wealth of knowledge and experience to provide readers with valuable insights and advice on a wide range of Linux-related topics.

    Share this article
    Shareable URL
    Prev Post

    3 Proven Methods to Lock and Unlock Users in Linux

    Next Post

    5 Ways To Use OR, AND, and NOT Operators with Grep[5 Simple Methods]

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Read next