Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is there a command line to find and delete duplicated entries in the /etc/apt/sources.list file?

or

is this possible via synaptic perhaps?

share|improve this question

7 Answers

For Ubuntu 12.04

Graphically:

Press Alt + F2 and paste software-properties-gtk (or you can open "Software Center" then go to "Edit" > "Software Sources"). Go to tab "Other Software", choose the duplicate entry and press the "Remove" button.

enter image description here


If you need a command line option, here it is:

cat /etc/apt/sources.list | perl -ne '$H{$_}++ or print' > /tmp/sources.list && sudo mv /tmp/sources.list /etc/apt/sources.list  

The command do this:

cat reads the file and passes the content to perl which will remove the duplicate lines. The result will be saved > in a temporary file which will then be moved to replace the original /etc/apt/sources.list file.

share|improve this answer

For Ubuntu 9.10 - 12.04

There is an app called Y-PPA-Manager which can do that and much more.

You can install it like that from a Terminal:

sudo add-apt-repository ppa:webupd8team/y-ppa-manager
sudo apt-get upgrade
sudo apt-get install y-ppa-manager

After that, just start the application an go to the Advanced menu.

main window

Then select "Scan and remove duplicate PPAs" and hit OK.

advanced window

share|improve this answer

Install ubuntu-tweak and remove the duplicate entries from there,it will be easy

for you..

sudo apt-get install ubuntu-tweak

alt text

share|improve this answer

10.10 and Earlier

Applications > Ubuntu Software Center > Edit > Software Sources > Other Software**

OR

System > Administration > Synaptic Packet Manager > Settings > Repositories**

alt text

Select and Remove duplicate entries.

share|improve this answer

Read this post: http://www.liberiangeek.net/2012/04/fix-duplicate-sources-list-entry-errors-in-ubuntu-12-04-precise-pangolin/

share|improve this answer
2  
Welcome to Ask Ubuntu! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – fossfreedom May 5 '12 at 9:25
This is already explained by askubuntu.com/a/131750/5538 – medigeek May 9 '12 at 7:17

I try to complete the possibilities offered from other users using terminal, since that's what you asked, mainly:

login if you're using a text based install or

Press alt+f2 and digit gnome-terminal if you're using GUI

once there digit

sudo nano /etc/apt/sources.list

(To understand better: in the folder /etc you can find (nearly) all configuration files of your computer and in the apt folder you find the souces.list file that contains all the repositories that apt-get uses to update or install and upgrade software)

edit visually the file removing or commenting with # the duplicated rows.

Press control + x to exit and choose y to save the file n to quit without saving.

Done that check your work with an update:

sudo apt-get update

Have fun!

share|improve this answer
I also think that evolved text editor like vim can automatically find duplicates but I don't know how to do that any kind of info would be interesting – Pitto Nov 18 '10 at 17:17

No, there isn't a single command line to find and delete duplicated entries in the /etc/apt/sources.list file.

This is because the suggested command lines, which merely duplicate the function of the much simpler built-in uniq command, will only work on a SORTED file and will only remove ADJACENT lines. Furthermore, those commands will only remove lines consisting of an identical string of characters.

Duplicate entries reported by apt-get update will consist of duplicate function entries, such as a repository being included in both its i386 and amd64 variants. The easy and effective way to remove these is to note which repositories are reported as duplicates by apt-get update and remove them via the Software Center. Open it and choose Edit -> Software Sources -> Other Software tab. Simply look for the duplicate entries and uncheck them. (This is also an opportunity to remove any source-code repositories if you're not compiling the packages).

However, it should be noted that apt-get update doesn't only find duplicate entries via sources.list, but includes repository files located in /var/lib/apt/lists/. Deleting duplicate entries from there will only temporarily remove the apt-get update error messages if Ubuntu thinks it needs them, as the files will be automatically re-installed. The fact that apt-get update will report some repositories as duplicates, and then suggest that that you run apt-get update itself to repair them, is a clue that you really don't need to worry about that error message.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.