Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to add a repository to apt-get (without potentially messing up /etc/apt/sources.list) through the user of a script. This script may run multiple times so I can't just append the entry each time. Is there any way I can add a single file in a directory with entries?

I know you can do this for yum, but I'm not sure if it's possible for apt-get. Please let me know if I need to add more info.

share|improve this question
If you double click on /etc/apt/sources.list, it opens a GUI interface with a wizard for adding repositories. There is a checkbox where you can enable and disable entries (e.g., to allow use of a new entry only when updating some "foreign" repository software), and entries can be deleted. It also creates a backup called in the same directory. If you want extra protection, you can always make a copy of the original file yourself before changing it. So there isn't much risk of messing up the file if you are going the script route just for that reason. – fixer1234 Jan 31 '15 at 5:16
up vote 17 down vote accepted

You can place files in /etc/apt/sources.list.d. This is described in the man page for sources.list (type man sources.list). The man page says:


The /etc/apt/sources.list.d directory provides a way to add sources.list entries in separate files. The format is the same as for the regular sources.list file. File names need to end with .list and may only contain letters (a-z and A-Z), digits (0-9), underscore (_), hyphen (-) and period (.) characters. Otherwise they will be silently ignored.

share|improve this answer
Thanks, this is exactly what I needed. – Daisetsu Jan 24 '11 at 21:19

You could try:

add-apt-repository <REPOSITORY LINE>

The repository line would just be what you would append to the sources.list or a PPA repository. Check out the manpage here, or execute:

man add-apt-repository
share|improve this answer
From a quick look at the man file for add-apt-repository it looks like it simply appends the line to the sources.list file, it doens't mention if it checks, so this is just the same as "echo line >> sources.list" which I already had. Thanks for responding though. – Daisetsu Jan 24 '11 at 21:20
@Daisetsu I know it does, I thought you just felt uncomfortable manually editing the file! Must've misunderstood! Great you got an answer that worked for you though! – BloodPhilia Jan 24 '11 at 21:33

I (thought that I) needed to add a ppa repo to a crunchbang, (debian) install:
(N.B. "raring" is the ubuntu version that matched the version of debian that I was using) so I did:

sudo su -

# you can call the file anything that you want, but it has to end with .list to be a valid for apt-get
echo 'deb raring main'>> /etc/apt/sources.list.d/boot-repair.list

# get the keys for that repo so that apt can verify the signed .deb files
apt-key add Release.gpg
#gpg --search-keys 60D8DA0B

apt-get update

Most of this is explained on the boot-repair page, (though in the end testdisk and then Gparted were what I actually needed to restore a lost partition and a corrupted MBR.) This probably isn't The Debian way (TM) but it worked for me.

Some debian repos are the "old style" and then you only need a line like:

deb /
# the trailing slash needs to be there

add-apt-repository is good if you have it, but that seems to be more ubuntu.

share|improve this answer

add-apt-repository has a third form (besides PPA URLs and full apt lines), which enables distribution components:

sudo add-apt-repository universe
sudo add-apt-repository contrib

This was introduced in 12.10 (Quantal).

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .