如何在 Debian 8.7 上删除重复的源列表

如何在 Debian 8.7 上删除重复的源列表

我正在运行 Debian 8.7,按照教程安装 #letsencrypt 后数字海洋。我无法再更新我的操作系统,如果我运行sudo apt-get update它,最后会显示以下错误

W: Duplicate sources.list entry ...ftp.debian.org/debian/ jessie-backports/main amd64 Packages (/var/lib/apt/lists/ftp.debian.org_debian_dists_jessie-backports_main_binary-amd64_Packages)
W: You may want to run apt-get update to correct these problems</code>

在其他情况下,要查看我的源列表,我运行以下代码cat /etc/apt/sources.list /etc/apt/sources.list.d/*

显示以下结果

deb http://httpredir.debian.org/debian/ jessie main
deb-src http://httpredir.debian.org/debian/ jessie main
deb http://security.debian.org/ jessie/updates main
deb-src http://security.debian.org/ jessie/updates main
deb http://httpredir.debian.org/debian/ jessie-updates main
deb-src http://httpredir.debian.org/debian/ jessie-updates main
deb http://http.debian.net/debian jessie main
deb-src http://http.debian.net/debian jessie main
deb http://ftp.debian.org/debian jessie-backports main
deb http://httpredir.debian.org/debian/ jessie-backports main
deb-src http://httpredir.debian.org/debian/ jessie-backports main
deb http://packages.cloud.google.com/apt cloud-sdk-jessie main
deb http://packages.cloud.google.com/apt google-cloud-compute-jessie main
deb http://packages.cloud.google.com/apt google-cloud-packages-archive-keyring-jessie main
deb http://packages.cloud.google.com/apt cloud-sdk-jessie main
deb http://packages.cloud.google.com/apt google-cloud-compute-jessie main
deb http://packages.cloud.google.com/apt google-cloud-packages-archive-keyring-jessie main
deb http://ftp.debian.org/debian jessie-backports main
deb http://ftp.debian.org/debian jessie-backports main

各位,我应该删除哪些资源,以及我应该采取什么代码或流程来删除它。我对这整个事情不太了解,我只是按照网上找到的说明去做所有事情。

答案1

重复的源列表是...ftp.debian.org/debian/ jessie-backports/main.。您需要将其删除。执行 agrep jessie-backports /etc/apt/sources.list.d/*grep jessie-backports /etc/apt/sources.list,查看哪些文件有它,用文本编辑器(例如 nano)打开它,删除它,然后刷新apt-get updateapt 的缓存。

答案2

根据您提到的 DigitalOcean 文档,我的钱花在:

rm -f /etc/apt/sources.list.d/backports.list
apt-get update

jessie-backports正如您所看到的,输出中有两个cat,...

答案3

如果你的系统能够运行 python。您可以使用以下 python3 脚本来制作不重复的文件副本。之后,您可以用新文件替换旧的“sources.list”

import os

l = set()
# remove duplicates by adding all the lines to a set
with open("/etc/apt/sources.list") as f:
    for line in f:
        l.add(line)
# write the new lines to a file in your home folder
with open("/home/brianbrix/sources.list", "w") as f:
    for line in l:
        f.write(line)
        f.write("\n")

# after that you can replace the sources file wwith the new one which has no duplicates

相关内容