sudo apt-get update
时,我会看到以下内容:W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Packages (main/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Translations (main/i18n/Translation-en_GB) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Translations (main/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target DEP-11 (main/dep11/Components-amd64.yml) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target DEP-11-icons (main/dep11/icons-64x64.tar) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Packages (restricted/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Packages (restricted/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Packages (restricted/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Translations (restricted/i18n/Translation-en_GB) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Translations (restricted/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target DEP-11 (restricted/dep11/Components-amd64.yml) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target DEP-11-icons (restricted/dep11/icons-64x64.tar) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Packages (multiverse/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Packages (multiverse/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Packages (multiverse/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Translations (multiverse/i18n/Translation-en_GB) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Translations (multiverse/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target DEP-11 (multiverse/dep11/Components-amd64.yml) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target DEP-11-icons (multiverse/dep11/icons-64x64.tar) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: The repository 'http://extras.ubuntu.com/ubuntu xenial Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: http://dl.google.com/linux/chrome/deb/dists/stable/Release.gpg: Signature by key 4CCA1EAF950CEE4AB83976DCA040830F7FAC5991 uses weak digest algorithm (SHA1)
W: http://repo.sinew.in/dists/stable/InRelease: Signature by key B6DA722E2E65721AF54B93966F7565879798C2FC uses weak digest algorithm (SHA1)
E: Failed to fetch http://extras.ubuntu.com/ubuntu/dists/xenial/main/source/Sources 404 Not Found [IP: 91.189.92.152 80]
E: Failed to fetch http://extras.ubuntu.com/ubuntu/dists/xenial/main/binary-amd64/Packages 404 Not Found [IP: 91.189.92.152 80]
E: Failed to fetch http://extras.ubuntu.com/ubuntu/dists/xenial/main/binary-i386/Packages 404 Not Found [IP: 91.189.92.152 80]
E: Some index files failed to download. They have been ignored, or old ones used instead.
W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Packages (main/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Translations (main/i18n/Translation-en_GB) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Translations (main/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target DEP-11 (main/dep11/Components-amd64.yml) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target DEP-11-icons (main/dep11/icons-64x64.tar) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Packages (restricted/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Packages (restricted/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Packages (restricted/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Translations (restricted/i18n/Translation-en_GB) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Translations (restricted/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target DEP-11 (restricted/dep11/Components-amd64.yml) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target DEP-11-icons (restricted/dep11/icons-64x64.tar) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Packages (multiverse/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Packages (multiverse/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Packages (multiverse/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Translations (multiverse/i18n/Translation-en_GB) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target Translations (multiverse/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target DEP-11 (multiverse/dep11/Components-amd64.yml) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
W: Target DEP-11-icons (multiverse/dep11/icons-64x64.tar) is configured multiple times in /etc/apt/sources.list:33 and /etc/apt/sources.list:87
是否有一种自动的方法来解决此问题?
#1 楼
最近的最新解决方案我编写了Python脚本来自动执行此任务。您可以在此处找到最新版本。
安装:
安装必备软件:
sudo apt install python3-apt
下载最新版本的PYZ捆绑包(
aptsources-cleanup.pyz
)。将PYZ捆绑包标记为可执行文件:
chmod a+x aptsources-cleanup.pyz
用法:
从PYZ软件包的下载位置(请参阅上面的步骤2)运行:
sudo ./aptsources-cleanup.pyz
按照屏幕上显示的说明进行操作。
如果您想报告问题,发表评论或分叉源代码,请在GitHub上进行。
历史性的过时解决方案
这是一个更旧,更短,更简单的版本,更适合于内联引用:
#!/usr/bin/env python3
"""
Detects and interactively deactivates duplicate Apt source entries.
Usage: sudo python3 apt-remove-duplicate-source-entries.py
"""
from __future__ import print_function
import aptsources.sourceslist
EMPTY_COMPONENT_LIST = (None,)
def get_duplicates(sourceslist):
"""
Detects and returns duplicate Apt source entries.
"""
sentry_map = dict()
duplicates = list()
for se in sourceslist.list:
if not se.invalid and not se.disabled:
for c in (se.comps or EMPTY_COMPONENT_LIST):
key = (se.type, se.uri, se.dist, c)
previous_se = sentry_map.setdefault(key, se)
if previous_se is not se:
duplicates.append((se, previous_se))
break
return duplicates
if __name__ == '__main__':
try:
input = raw_input
except NameError:
pass
sourceslist = aptsources.sourceslist.SourcesList(False)
duplicates = get_duplicates(sourceslist)
if duplicates:
for dupe, orig in duplicates:
print(
'Overlapping source entries:\n'
' 1. {0}: {1}\n'
' 2. {2}: {3}\n'
'I disabled the latter entry.'.format(
orig.file, orig, dupe.file, dupe),
end='\n\n')
dupe.disabled = True
print('\n{0} source entries were disabled:'.format(len(duplicates)),
*[dupe for dupe, orig in duplicates], sep='\n ', end='\n\n')
if input('Do you want to save these changes? (y/N) ').upper() == 'Y':
sourceslist.save()
else:
print('No duplicated entries were found.')
它不带任何参数并且可以正常工作在所有
/etc/apt/sources.list*
上借助python3-apt
软件包。行不必完全相同(即使在归一化之后)也可以,但是如果类型,URI,套件和至少一个组件重叠,则行就足够了。我不确定在所有极端情况下均等测试是否正确(例如各种“选项”字符串)。
评论
您可以从终端通过命令wget“github.com/davidfoerster/aptsources-cleanup/releases/download/…”下载它。
–萨米人
19年1月22日在8:56
@Sami:是的,但是当我发布另一个版本时,它将不再指向最新版本。
–大卫·福斯特(David Foerster)
19年1月22日在13:34
osboxes @ osboxes:/etc/apt/sources.list.d$ sudo python3 -OEs aptsources-cleanup.zip python3:无法打开文件“ aptsources-cleanup.zip”:[错误2]没有此类文件或目录
–工具包
19年7月30日在4:33
@Toolkit:我修改了使用说明。请阅读它们,然后重试。抱歉,缺乏清晰性。
–大卫·福斯特(David Foerster)
19年7月30日在23:55
我从第1行收到SyntaxError:语法无效,从zip运行脚本。克隆git仓库并从那里运行可以。
–glS
19-10-13在21:09
#2 楼
对我来说(16.04 LTS)转到系统设置>>软件和更新>>其他软件,然后从列表中删除每个重复的条目都很好。
评论
我要求一种自动方法。
– Tim
16年11月6日在10:58
这是比执行它之前阅读国外python3脚本更好的解决方案。。。
–卢克
17年8月28日在12:06
您可以删除具有不同类型的“重复项”吗?例如,我有http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main和http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main(源代码)。是否可以删除一个(源代码)(而不选择另一个,而不检查另一个)?
–德鲁伊特
18年1月1日在10:02
@Tim是真的,但这可能不是大多数人来问这个问题的原因
– joel
19年1月23日在10:19
@Deruijter说“源代码”的代码不被视为与另一个代码的重复。但是,除非您想下载某些软件包的源代码以自行编译它们,否则不需要显示“源代码”的代码。
– mchid
19年7月4日在8:27
#3 楼
重设存储库,如下所示:重要信息:首先验证是否已安装
software-properties-gtk
(可以运行software-properties-gtk -h
以验证是否获得帮助消息)sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak
sudo software-properties-gtk
选择选项
保存
一旦一切正常,您就可以使用
sudo rm -rf /etc/apt/sources.list.bak
删除备份。评论
请注意,只有在检查并确保您的系统上确实安装了software-properties-gtk后,您才应该这样做。不要问我是什么让我写了这个。
–MilošĐakonović
19年8月15日在8:15
为此添加了一些修改...因为...嗯...没有理由...
– j6m8
19/12/27在15:43
打开software-properties-gtk后,我看不到任何重复项。我在Ubuntu 20.04 LTS上。
–Shreck Ye
20年6月16日在14:28
#4 楼
由于错误会告诉您问题出在哪里,并且所有问题都是由一条重复的行引起的,因此您可以使用vim,nano等文本编辑器轻松手动修复此问题。这样做的好处是您可以准确看到问题是什么以及要解决的问题。对于您的情况,使用sudo或以root身份在文本编辑器中打开/etc/apt/sources.list。删除第33行或第87行。您可以直观地检查它们是否是重复项。
如果您喜欢vim ...
$ sudo vim /etc/apt/sources.list
33 [Shift]+g # to goto line 33
87 [Shift]+g # to goto line 87, don't need a duplicate of line 33
dd # to delete the line you're on
:wq # to write the file and quit
或者,如果遇到错误,请走出去...
:q! # to quit without saving any changes
评论
我在/etc/apt/sources.list.d/google-cloud-sdk.list中遇到了类似的问题。这对我有用。谢谢!
–akhilsp
20 Mar 13 '20 at 5:57
谷歌浏览器类似的问题。两个.list文件中的条目相同,我使用此方法在其中一个中删除。
–杰斐逊
20/12/3在13:46
#5 楼
对于具有Linux Mint的基于Ubuntu的系统,请转至软件源>维护>删除重复的软件包评论
这样做我没有发现重复,但仍然看到相同的错误
–cipricus
19年8月27日在12:31
评论
我看到了很多“解决方案”,但没有解释为什么会发生这种情况。@PJBrunet这个问题没有问为什么,它要求他修复它。随意问一个新的问题,重点是为什么。