如何从 Ubuntu 中删除软件仓库
软件仓库
![](/data/attachment/album/202307/10/164855dgguejdcbv5uqkj6.jpg)



> 
> 从 `apt-add-repository` 到“软件及更新”工具，这里有几种从 Ubuntu 移除软件仓库的方法。
> 
> 
> 


你可以 [在 Ubuntu 中添加外部仓库](https://itsfoss.com/adding-external-repositories-ubuntu/) 来访问官方仓库中不可用的软件包。


例如，如果你 [在 Ubuntu 中安装 Brave 浏览器](https://itsfoss.com/brave-web-browser/)，则将其仓库添加到你的系统中。如果你添加了一个 PPA，它也会添加为外部仓库。


当你不需要特定软件时，请将其删除。但是，外部仓库仍然存在。你还可以也应该将其删除以保持系统原始状态。


Ubuntu 可以让你轻松删除软件仓库。有不同的方法可以做到这一点：


* 使用 `apt-add-repository` 命令删除仓库
* 使用 GUI 删除仓库（对于桌面用户）
* 通过修改 `/etc/apt/sources.list` 文件的文件内容（针对专家）


但在此之前，如果你对这个概念不熟悉，我强烈建议你 [熟悉包管理器的概念](https://itsfoss.com/package-manager/) 和仓库。


### 方法 1、使用 apt 删除仓库?


你知道你还可以使用 [apt 命令](https://itsfoss.com/apt-command-guide/) 来删除仓库吗？ 嗯，从技术上讲，它不是核心 `apt` 命令的一部分，但它的工作方式类似。


在处理外部仓库时，你可以使用 `add-apt-repository` 或者 `apt-add-repository` 命令（两者是同一命令）。


首先，使用以下命令列出添加的仓库：



```
apt-add-repository --list

```

![list enabled repositories in Ubuntu](/data/attachment/album/202307/10/164926z363plfm6u91fb6e.png)


完成后，你可以按所示方式使用带有 `-r` 标志的 `apt-add-repository` 命令来从列表中删除：



```
sudo apt-add-repository -r repo_name

```

例如，如果我想删除 `yarn` 仓库，我必须使用以下命令：



```
sudo add-apt-repository -r deb https://dl.yarnpkg.com/debian/ stable main

```

![Remove repository using the apt-add-repository command in Ubuntu](/data/attachment/album/202307/10/164927mtmbffl707dxgkxg.png)


按回车键进行确认。


接下来，使用以下命令更新仓库：



```
sudo apt update

```

现在，如果你列出已启用的仓库，你将不会在此处找到已删除的仓库：



```
apt-add-repository --list

```

![confirm repository removal process by listing enabled repositories in Ubuntu](/data/attachment/album/202307/10/164927jmhfqwckgbgxhfdf.png)


这就完成了！


### 方法 2、使用 GUI 删除 Ubuntu 中的软件仓库?️



> 
> ? 不建议删除你一无所知的仓库，因为它可能会限制你将来安装你最喜欢的软件包，因此请确保你知道自己在做什么。
> 
> 
> 


作为 [最适合初学者的发行版之一](https://itsfoss.com/best-linux-beginners/)，你可以使用 GUI 来删除仓库，而无需使用终端。


为此，首先从系统菜单打开“<ruby> 软件及更新 <rt>  software &amp; updates </rt></ruby>”应用：


![search for software and updates from the system menu](/data/attachment/album/202307/10/164928yydduj969tdqyu9d.png)


现在，单击“<ruby> 其他软件 <rt>  Other Software </rt></ruby>”部分，它将列出系统中的 PPA 和外部仓库。


列出中勾选的 ✅ 是已启用的。


要删除仓库，你必须遵循**三个简单的步骤**：


* 选择需要删除的仓库
* 点击“<ruby> 删除 <rt>  Remove </rt></ruby>”按钮
* 最后，点击“<ruby> 关闭 <rt>  Close </rt></ruby>”按钮


![Disable repository from Ubuntu](/data/attachment/album/202307/10/164928ujfyhg68ahjj8svz.png)


单击关闭按钮后，它将打开一个提示，要求你在进行更改时更新信息。


只需单击 “<ruby> 重新载入 <rt>  Reload </rt></ruby>” 按钮即可：


![Click on reload to after removing repository from Ubuntu and save changes](/data/attachment/album/202307/10/164928sw6nxlz67uj5uudx.png)


或者，你可以从命令行更新仓库以使更改生效：



```
sudo apt update

```

### 方法 3、通过目录来删除仓库（对于专家?‍?）


之前，我解释了如何使用工具（GUI 和 CLI）来删除仓库。在这里，你将修改负责管理仓库的系统目录（`/etc/apt/sources.list.d`）。


首先，将工作目录更改为 `sources.list.d` 并列出其内容：



```
cd /etc/apt/sources.list.d/ && ls

```

![list contents of sources.list.d directory](/data/attachment/album/202307/10/164929i8r8wmy4qigzesh0.png)


在这里，你将找到所有仓库的列表。


如果你仔细观察，一个仓库将有两个文件。一个带有 `.list` 扩展名，另一个带有 `.save` 扩展名。


你必须删除具有 `.list` 扩展名的文件：



```
sudo rm Repo_name.list

```

例如，在这里，我使用以下命令删除了 **node 仓库**：



```
sudo rm nodesource.list

```

![remove repository by removing the repository directory in Ubuntu](/data/attachment/album/202307/10/164929vrdjgg4fd47fhdhz.png)


要使更改生效，请使用以下命令更新仓库索引：



```
sudo apt update

```

想了解更多有关 [sources.list](https://itsfoss.com/sources-list-ubuntu/) 的信息吗？阅读 [这篇文章](https://itsfoss.com/sources-list-ubuntu/)。


### 附加步骤：删除仓库后删除 GPG 密钥（对于高级用户）


如果你希望在删除仓库后删除 GPG 密钥，请按以下步骤操作。


首先，使用以下命令列出现有的 GPG 密钥：



```
apt-key list

```

现在，输出可能会让某些用户感到困惑。


以下是要记住的事情：


* GPG 密钥名称将放置在虚线（`----`）上方
* 公钥在第二行


例如，以下是 Chrome GPG 密钥的相关数据：


![list GPG keys in Ubuntu](/data/attachment/album/202307/10/164929xyg7q5765p55x6g7.png)


要删除 GPG 密钥，你可以使用公钥的最后两个字符串（不带任何空格）。


例如，以下是我将如何使用 Chrome 浏览器公钥的最后两个字符串（D38B 4796）删除其 GPG 密钥：



```
sudo apt-key del D38B4796

```

![remove GPG key in Ubuntu](/data/attachment/album/202307/10/164929haa6uwu9fo4d9wwu.png)


同样，你也可以使用整个公钥。但这一次，你必须在两个字符串之间包含空格，如下所示：



```
sudo apt-key del "72EC F46A 56B4 AD39 C907  BBB7 1646 B01B 86E5 0310"

```

### 小心添加和删除的内容


特别是当你是 Linux 新用户时，你会遇到许多感兴趣的软件，对仓库添加了又删除。


虽然尝试是件好事，但你应该始终小心添加/删除到系统中的任何内容。你应该记住一些事情，例如：*它包含更新的软件包吗？ 它是受信任或维护的仓库吗？*


保持谨慎将使你的系统免受不必要的仓库和软件包的影响。


**我希望本指南可以帮助你删除不需要的仓库！**


如果你遇到任何问题请在下面评论。


*（题图：MJ/3d436ed6-76fc-47ef-88c3-b5f3e2862c7d）*




---


via: <https://itsfoss.com/remove-software-repositories-ubuntu/>


作者：[Sagar Sharma](https://itsfoss.com/author/sagar/) 选题：[lkxed](https://github.com/lkxed/) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

You can [add external repositories in Ubuntu](https://itsfoss.com/adding-external-repositories-ubuntu/) to access packages unavailable in the official repositories.

For example, if you [install Brave browser in Ubuntu](https://itsfoss.com/brave-web-browser/), you add its repository to your system. If you add a PPA, that is added as an external repository too.

When you don't need the specific software, you remove it. However, the external repository is still added. You can, and you should also remove it to keep your system pristine.

Ubuntu lets you remove a software repository easily. There are different ways to do that:

**Using apt-add-repository command to remove the repository****Using GUI to remove the repository (for desktop users)****By modifying the file contents of the /etc/apt/sources.list file (for experts)**

But before that, I highly advise [getting familiar with the concept of package managers](https://itsfoss.com/package-manager/) and repositories if you are new to this concept.

[What is a Package Manager in Linux?Learn about packaging system and package managers in Linux. You’ll learn how do they work and what kind of package managers available.](https://itsfoss.com/package-manager/)![](https://itsfoss.com/content/images/wordpress/2020/10/linux-package-manager-explanation.png)


![](https://itsfoss.com/content/images/wordpress/2020/10/linux-package-manager-explanation.png)

## Method 1. Remove the repository using apt 🤖

Did you know you can also use the [apt command](https://itsfoss.com/apt-command-guide/) to remove repositories? Well, technically, it's not part of the core apt command but it works in similar fashion.

You can use the `add-apt-repository`

or `apt-add-repository`

commands (both represent the same command) while dealing with external repositories.

First, list the added repositories using the following command:

`apt-add-repository --list`


![list enabled repositories in Ubuntu](https://itsfoss.com/content/images/2023/06/list-enabled-repositories-in-Ubuntu.png)

Once done, you can use the apt-add-repository command with the `-r`

flag in shown manner to remove the directory:

`sudo apt-add-repository -r repo_name`


For example, if I want to remove the **yarn** repository, I would have to use the following command:

`sudo add-apt-repository -r deb https://dl.yarnpkg.com/debian/ stable main`


![Remove repository using the apt-add-repository command in Ubuntu](https://itsfoss.com/content/images/2023/06/Remove-repository-using-the-apt-add-repository-command-in-Ubuntu.png)

Press the **Enter** key for confirmation.

Next, update the repositories using the following:

`sudo apt update`


And now, if you list enabled repositories, you won't find the removed repository here:

`apt-add-repository --list`


![confirm repository removal process by listing enabled repositories in Ubuntu](https://itsfoss.com/content/images/2023/06/confirm-repository-removal-process-by-listing-enabled-repositories-in-Ubuntu.png)

There you have it!

[Using apt Commands in Linux [Ultimate Guide]This guide shows you how to use apt commands in Linux with examples so that you can manage packages effectively.](https://itsfoss.com/apt-command-guide/)![](https://itsfoss.com/content/images/wordpress/2017/07/apt-commands-example.png)


![](https://itsfoss.com/content/images/wordpress/2017/07/apt-commands-example.png)

## Method 2. Remove the software repository in Ubuntu using GUI 🖥️

Being [one of the best distros for beginners,](https://itsfoss.com/best-linux-beginners/) You can use GUI to remove the repository without needing the terminal.

To do so, first, open the software and updates the app from the system menu:

![search for software and updates from the system menu](https://itsfoss.com/content/images/2023/06/search-for-software-and-updates-from-the-system-menu.png)

Now, click on `Other Software`

section, and it will list PPAs and external repositories in your system.

The ones listed as checked ✅ are enabled ones.

To remove a repository, you'd have to follow **three simple steps**:

**Select a repository that needs to be removed****Click on the remove button****And finally, hit the close button**

![Disable repository from Ubuntu](https://itsfoss.com/content/images/2023/06/remove-the-repository-from-Ubuntu-using-GUI-1.png)

Once you click on the close button, it will open a prompt asking you to update the information as you make changes.

Simply click on the `Reload`

button:

![Click on reload to after removing repository from Ubuntu and save changes](https://itsfoss.com/content/images/2023/06/Click-on-reload-to-after-removing-repository-from-Ubuntu-and-save-changes.png)

Alternatively, you can update the repository from the command line to take effect from the changes:

`sudo apt update`


## Method 3. Remove the repository by removing its directory (for experts 🧑💻)

Previously, I explained how you could use tools (GUI and CLI) to remove a repository; here, you will modify the system directory (**/etc/apt/sources.list.d**) responsible for managing repositories.

So first, change your working directory to `sources.list.d`

and list its contents:

`cd /etc/apt/sources.list.d/ && ls`


![list contents of sources.list.d directory](https://itsfoss.com/content/images/2023/06/list-contents-of-sources.list.d-directory.png)

Here, you will find the list of all the repositories.

If you notice carefully, there will be two files for one repo. Once with the `.list`

extension and one with the `.save`

extension.

You will have to remove the one having the `.list`

extension:

`sudo rm Repo_name.list`


For example, here, I removed the **node repo** using the command below:

`sudo rm nodesource.list`


![remove repository by removing the repository directory in Ubuntu](https://itsfoss.com/content/images/2023/06/remove-repository-by-removing-the-repository-directory-in-Ubuntu.png)

To take effect from the changes, update the repository index with:

`sudo apt update`


Want to know more about the [sources.list](https://itsfoss.com/sources-list-ubuntu/)? Read this article.

[What is the Use of sources.list File in Ubuntu Linux?Understanding the concept of sources.list in Ubuntu will help you understand and fix common update errors in Ubuntu.](https://itsfoss.com/sources-list-ubuntu/)![](https://itsfoss.com/content/images/2022/12/sources-lits-file-ubuntu.png)


![](https://itsfoss.com/content/images/2022/12/sources-lits-file-ubuntu.png)

## Additional Step: Remove GPG keys after removing the repository (for advanced users)

If you wish to remove the GPG keys after removing the repository, here's how you do it.

First, list the existing GPG keys using the following command:

`apt-key list`


Now, the output may seem confusing to some users.

Here's what to remember:

- The GPG key name will be placed above the dashed line (----)
- The public key is in the second line

For example, here's the relevant data of the Chrome GPG key:

![list GPG keys in Ubuntu](https://itsfoss.com/content/images/2023/06/list-GPG-keys-in-Ubuntu.png)

To remove the GPG key, you can use the last two strings of the public key (without any space).

For example, here's how I will remove the GPG key of the Chrome browser using the last two strings of its public key (D38B 4796):

`sudo apt-key del D38B4796`


![remove GPG key in Ubuntu](https://itsfoss.com/content/images/2023/06/remove-GPG-key-in-Ubuntu.png)

Similarly, you can also use the entire public key. But this time, you have to include spaces between two strings, as shown:

`sudo apt-key del "72EC F46A 56B4 AD39 C907 BBB7 1646 B01B 86E5 0310"`


## Careful with what you add and what you remove

Especially when you are a new Linux user, you will encounter many exciting things and repositories you will add and remove.

While it is good to experiment, you should always be careful about anything you add/remove to your system. You should keep some things in mind, like: *Does it include updated packages? Is it a trusted or maintained repository?*

Being cautious will keep your system free from unnecessary repositories and packages.

**I hope this guide helps you remove the repository you do not want! **

*Feel free to let me know if you face any issues in the comments below, and consider joining our It's FOSS Community forum to get faster help! *