How to remove a repository in Ubuntu via 3 Methods

Endrit Qerreti

Endrit Qerreti

In this tutorial, you will learn how to remove a repository in Ubuntu, via three different methods.

When you download softwares via a repository in Ubuntu, removing the software won't remove its repository automatically.

In such cases, the repository of the removed softwares has be to removed manually from your system.

In this tutorial, we'll be removing a repository in Ubuntu by using the terminal, and by using GUI.

Remove a repository in Ubuntu

In the first method, you will learn how to remove a repository in Ubuntu by manually removing the repository from your source.list file. This file contains all the repositories that are active in your system.

In the second method, you will learn how to remove a repository, by deleting a repository file from the sources.list.d directory.

In the third method, you will learn how to remove a repository via Software Manager.

Method 1 : Remove a repository manually from sources.list

source.list is the file that contains the repositories that you have added in your Ubuntu system.

When you add a new repository in Ubuntu, you can either add it manually in your sources.list file, or create a new repository file in the sources.list.d directory.

So when it comes to removing a repository manually in Ubuntu, you must know where the repository was added.

For example, let's say that you added the repository to sources.list, so in order to remove that repository, first you must open sources.list via a text editor.

sudo nano /etc/apt/sources.list

Once sources.list is opened in your terminal, there are two way to remove a repository.

1) You can remove a repository by commenting out the repository.

Commenting out a repository will turn that repository into a comment line, which means the repository won't be deleted from sources.list but it won't be enabled. So next time you update your package database, the repository that you commented out will be seen as a comment by the system.

Let's say we want to remove the universe repository in Ubuntu. To do so, simply add # in he beginning of the repository line.

The repository should look like this.

2) You can remove a repository by manually deleting the repository.

If you don't want to keep a copy of the repository that you want to remove, then you can easily delete the repository source.

First select the repository that you want to remove, to do so, use your arrow keys and move the cursor to the line that you want to remove.

Next, press CTRL + K and repository will be deleted.

Depending the method you chose to remove the repository.

Make sure to save changes by pressing CTRL + X

Next, confirm by pressing Y key.

And finally press enter.

Method 2: Delete a repository from sources.list.d directory

Like we said, depending on the software, some software add their own repository into a repository file which is located in the sources.list.d directory.

For example, if you install Node.js via its own repository, then its repository nodesource.list gets added into the sources.list.d directory.

You can easily locate the repository you want to delete, by using the ls command as shown in the screenshot below.

ls /etc/apt/sources.list.d/

If you have multiple repositories in the sources.list.d directory, then you can sort by the repository name

For example, to look only for nodesource repository, then simply run the command below.

cd /etc/apt/sources.list.d/ && ls node*

So to remove Node.js repository, you need to manually delete the repository file via the rm command.

sudo rm /etc/apt/sources.list.d/nodesource.list

Method 3 : Remove a repository using Software Manager

Software Manager allows you to easily add or remove any repository from your Ubuntu system.

To do so, first launch Software Manager via Applications Menu.

Next, go to "Other Softwares" Tab

Now simply select the Repository that you want to remove

Once you have selected the repository that you want to remove, click to "Remove" button.

Next, you will be prompted to authenticate in order to remove the repository.

As you can see in the screenshot below, the repository is now removed.

Now, you need to click to "Close" button to proceed updating the package database.

Next, confirm that you want to update the package database, by clicking the "Reload" button.

That's it! The repository is now removed, and package database is also updated.

Conclusion

In this tutorial, you learned how to remove a repository in Ubuntu via 3 different methods.

In the first method, we removed the repository by manually editing source.list file.

In the second method, we removed a repository by deleting the repository source file from the source.list.d directory.

In the third method, we removed a repository by using GUI, via Software & Updates app.