298

I just installed Ubuntu Gnome 16.04. I told it to save my documents - which worked. Some software had to be reinstalled. Now when I run sudo apt-get update I see this:

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

Is there an automated way to fix this?

muru
  • 197,895
  • 55
  • 485
  • 740
Tim
  • 32,861
  • 27
  • 118
  • 178

8 Answers8

348

Recent, up-to-date solution

I wrote a Python script to automate this task. You can find the most recent version here.

Installation:

  1. Install the prerequisites:

    sudo apt install python3-apt
    
  2. Download the PYZ bundle (aptsources-cleanup.pyz) from the latest release.

  3. Mark the PYZ bundle as executable:

    chmod a+x aptsources-cleanup.pyz
    

Usage:

  1. From the download location of the PYZ bundle (see step 2 above) run:

    sudo ./aptsources-cleanup.pyz
    
  2. Follow the instructions appearing on the screen.

If you wish to report an issue, leave a comment, or fork the source code, please do so on GitHub.


Historical, outdated solution

This is an older, shorter and simpler version more suitable to inline quotation:

#!/usr/bin/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.')

It takes no parameter and works on all /etc/apt/sources.list* with the help of the python3-apt package. Lines don't have to be exact duplicates (even after normalization) but its enough if type, URI, suite and at least one component overlap.

I'm not sure the equality test is correct in all corner cases (e. g. various “option” strings).

David Foerster
  • 36,264
  • 56
  • 94
  • 147
  • I get a SyntaxError: invalid syntax on line 1 running the script from the zip. Cloning the git repository and running from there works though. – glS Oct 13 '19 at 21:09
  • 1
    @glS: Could you please report the issue and include 1) the command line used to invoke the program and 2) its full output? Thanks. – David Foerster Oct 15 '19 at 06:44
  • 1
    thanks, I did , after extracting the zip file, sudo python3 main.py and answered the questions(yes for saving the changes, yes for removing an now-empty file). – Chan Kim Oct 25 '19 at 06:58
  • 2
    THANKYOU!!! - Microsoft with the edge dev/edge beta repositories scrambled apt's brains on my MATE box, this is been driving me nuts!! - fixed it in 30 seconds thanks to your answer! – shawty Aug 25 '21 at 19:56
  • @tribbloid: Could you please create an issue report with the offending Apt source lists attached? I’ll be sure to have a look at it. Thank you. – David Foerster May 06 '22 at 20:24
160

For me (16.04 LTS) going to

System settings >> Software and Updates >> Other Software and removing each duplicate entry from the list worked fine.

Tim
  • 32,861
  • 27
  • 118
  • 178
learner
  • 1,834
  • 2
  • 12
  • 19
  • 8
    I was requesting an automated method. – Tim Nov 06 '16 at 10:58
  • 56
    this is a better solution than read foreign python3 script before executing it... worked perfectly – Luke Aug 28 '17 at 12:06
  • 10
    Can you delete "duplicates" which have a different type? For example I have http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main and http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main (source code). Is it save to remove the (source code) one (this one isn't checked either, as opposed to the other one)? – Deruijter Mar 01 '18 at 10:02
  • @Deruijter: Could you please open a new question if you have a new or follow-up question? The comment section is not suitable or meant for new questions or extended discussion. You’re welcome to send me a comment with a notification to draw my attention to it. Thanks. – David Foerster Jun 13 '18 at 18:07
  • 7
    @Tim true but that's probably not why most people come to this question – joel Jan 23 '19 at 10:19
  • @Deruijter I assume it is fine, but let me know if you found any other answers. – Mario Olivio Flores Jan 30 '19 at 10:34
  • 1
    For 18.10 with KDE this didn't work exactly, but going to the dash and typing in "updates" quickly led to the right place. – Zach Boyd Feb 28 '19 at 14:43
  • On Linux Mint 18 (also based on LTS 16.04) it's System Settings >> Software Sources (under Administration) >> Additional Repositories. Then remove each duplicate and click "update cache". – Ben A. Hilleli Mar 26 '19 at 18:27
  • 9
    @Deruijter The one that says "source code" is not considered a duplicate of the other one. However, you don't need the one that says "source code" unless you would like to download the source code for some packages to compile them on your own. – mchid Jul 04 '19 at 08:27
  • This does not work for me, I still get the errors after removing all apparent duplicates. – Caleb Stanford Apr 01 '21 at 01:08
  • @DavidFoerster I strongly disagree, "follow up" and "clear up" questions *should* be asked and resolved in comments - that is one of the main purposes of comments, if however it would be an "another question" then of course > new main question; but this was a clearup since the answer is a bit ambiguous. – jave.web Feb 15 '23 at 23:46
  • @CalebStanford well if your errors/warnings are about duplicate definitions - they usually contain information about where the definitions are - so you can alway see and edit those .list files manually :-) – jave.web Feb 15 '23 at 23:53
  • @jave.web I don’t see how the safety of the removal of source code package source entries relates to the process of the removal of duplicate package source entries. They’re very different questions that happen to be about neighbouring subjects. – David Foerster Feb 17 '23 at 02:46
  • @DavidFoerster I know what you're trying to say, but unfortunately here, specifically, you're not correct, the concern was whether the .source is also a duplicate - therefore whether it's safe or not to remove it. The follow up was not a generic question about "is it safe to delete .source" repos. However still - *any data removal should have information about any potential risks as close as possible :-)* it may not be word-to-word with generic rules, but it is the right thing to do. – jave.web Feb 20 '23 at 10:58
45

Reset your repositories like this:

  1. IMPORTANT: First verify that you have software-properties-gtk installed (you can run software-properties-gtk -h to verify that you get a help-message)
  2. sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak
  3. sudo software-properties-gtk
  4. Pick your options
  5. Save

Once everything is working, you can then delete your backup with sudo rm -rf /etc/apt/sources.list.bak.

j6m8
  • 103
  • 3
Andrew
  • 1,535
40

Since the errors tell you where the problem is, and that all the problems are due to a single duplicated line, you can easily fix this manually with a text editor like vim, nano, etc. One benefit of this is that you can see exactly what the problem is and what you're doing to fix it.

In your case, with sudo or as root, open /etc/apt/sources.list in a text editor. Delete either line 33 or line 87. You can visually check that they're duplicates first.

If you like 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

Or, to get out if you make a mistake...

:q!             # to quit without saving any changes
mightypile
  • 1,192
  • 3
    I had a similar issue with /etc/apt/sources.list.d/google-cloud-sdk.list. This worked for me. Thanks! – akhilsp Mar 13 '20 at 05:57
  • 1
    Similar issue with google-chrome. Same entry in two .list files and I used this approach to delete in one of them. – Jefferson Dec 03 '20 at 13:46
  • 2
    @mightypile I upvoted simply because yes... I do like vim. Oh yeah, and I also wanted a cli solution. :,) – zedmelon Mar 14 '21 at 16:48
  • 1
    I think this is the "correct" solution, because it actually teaches you where the repos are defined, what issue is, and you can fix it easily yourself. Upvoted. – P.R. Jun 15 '23 at 12:55
8

For Ubuntu-based systems with Linux mint, go to Software Sources > Maintenance > Remove Duplicate packages

6

Similar to Other Answers, BUT ...

I had to look in /etc/apt/sources.list.d. Two of the list files in that directory were trying to reference the same things.

I kept the list file that was referencing more things. Problem solved.

Thom Ives
  • 193
  • 1
  • 5
  • 4
    Sometimes it does not work otherwise. I had to peek into the /etc/apt/sources.list.d. Thanks for pointing to the solution. +1! – loved.by.Jesus May 13 '22 at 13:20
  • 1
    All my warnings had the same line number at the end. I commented out that one line and all the errors went away. – Philip Rego Oct 22 '23 at 00:16
1

Manually edit /etc/apt/sources.list and remove duplicated lines.

logbasex
  • 349
0

I do not think that this is a useful advice for your problem with the Ubuntu installer that you cannot control. Yet, if you just have this error after writing some installation commands yourself instead, this might perhaps help:

In a Dockerfile for a python2 ROS project and a lot of installed apt-get packages before the error, I got another error first: /bin/sh: 1: python-matplotlib: not found, although it is a known package in apt-get. Then I switched to python -m pip install -y matplotlib sympy which caused the error of the question: #13 3.422 W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list.d/ros-latest.list:1 and /etc/apt/sources.list.d/ros1-latest.list:1. At this point, you might consider testing python2.7 -m pip install -y matplotlib sympy as well according to this. Then I switched back to

apt-get install -y python-matplotlib python-sympy

and I also kept that line apart from other apt-get installations.

The steps may not all be needed, I just did not want to take out any of them since I can only guess the reasons. A small share of the finally working Dockerfile:

RUN apt-get install --upgrade python-pip -y && \
    python -m pip install --upgrade pip
# I have seen during installation that the default fell back to Python3.7 for at least one package:
RUN apt-get install -y MANY_PYTHON2_PACKAGES_PERHAPS_INSTALLED_WITH_PYTHON3.7_DEFAULT
# These packages perhaps need another Python version than the previous?
RUN apt-get install -y python-matplotlib python-sympy
RUN python -m pip install MANY_PYTHON2_PACKAGES_NOT_IN_APT-GET

UPDATE: I had the error again when update ran. I simply dropped the update. That worked because it had run a couple of lines before anyway:

From:

RUN apt-get -o Acquire::Check-Valid-Until=false update && \
    apt-get install -y ...

to

RUN apt-get install -y ...