How To easily add a testing/unstable repository to your Debian and switch between them

In this article I will tell you how to add any Debian repository with the ability to use it at any time you need.

For example, your current repository is stable. But suddenly you need a fresh version of the package, which is in a testing or unstable (sid) repository. Then you can easily add them and use them at any time convenient for you.

There is a very simple way to do this without setting priorities and other things. You just use these repositories when you really want it. OK, let’s do it.

Step by step. Specify our default repository

First, Go to /etc/apt/apt.conf.d directory

cd /etc/apt/apt.conf.d

Then, create a 99defaultrelease file in it

touch 99defaultrelease

Then open it and write your current default repository, so if my current default repository is stable, then I write

APT::Default-Release "stable";

Then go to /etc/apt/sources.list.d direcory

cd /etc/apt/sources.list.d

Here you can add as many repositories as you like.

Unstable, experimental, testing and stable repositories. Their relationship to each other on freshness of packages.
This is how it works. As you can see, the latest versions of the packages arrive in a unstable and experimental repository.

Start to specify additional repositories. How to add unstable repository

For example, we only want to add an unstable repository. Then we need create a file unstable.list in /etc/apt/sources.list.d directory

touch unstable.list

And write in it following URL addresses and options

deb     http://ftp.uk.debian.org/debian/    unstable main contrib non-free
deb-src http://ftp.uk.debian.org/debian/    unstable main contrib non-free
#deb     http://security.debian.org/         unstable main contrib non-free

Here I use English servers (I highlighted subdomains in bold), so you can change to any other. To choose the right server, check your /etc/apt/sources.list

cat /etc/apt/sources.list

And look, what servers do you use now, these are the servers that you chose when you installed Debian. You need exactly URL address. Or you can use this page (Debian worldwide mirror sites) to choose the needed servers. The geographical location of the server affects the speed of downloading packages.

I commented out the last line, because it is responsible for security packages, I don’t in any way want to use security packages from an unstable repository, so I commented out this line to make sure.

Then update the list of available packages.

sudo apt-get update

As you noticed, the information was downloaded from both the unstable and stable(if you use it) repository.

How to install unstable (sid) packages now?

You can install them this way

sudo apt-get -t unstable install some_package

It’s easy, right?

So, if you enter just

sudo apt-get install some_package

The package will be installed from the stable repository (if it is your default one).

How to add a testing repository

First, create a file testing.list in /etc/apt/sources.list.d directory

touch testing.list

And add following lines

deb     http://ftp.uk.debian.org/debian/    testing main contrib non-free
deb-src http://ftp.uk.debian.org/debian/    testing main contrib non-free
#deb     http://security.debian.org/         testing main contrib non-free

Don’t forget to change the geographical location of the package server.

Then update the package list by command

sudo apt-get update

Now you can easily install packages from the testing repository with the command

sudo apt-get -t testing install some_package

Thanks for attention!