How to install a single package from debian testing through apt

Rate this post

Why would you want to install a package from testing when running on stable?

The reason is simple. Sometimes you just need a later version of a package than is in the Debian Stable repository. You could of course compile it from source, but this was not good enough for me since if you compile it from source, you have to keep it updated manually, and i’m sure i will forget to.
I wanted to do it through apt like the normal packages, But at the same time still keep running on Debian stable but having the option to install a later version of a package.

In this post, i will show you how you can make that possible, and it’s really easy!

What you will need

Only the info in this post and your running debian system.

How to install a single package from debian testing

Adding the apt configuration that allows this

Add the following line to the file /etc/apt/apt.conf (if the file does not exists, create it)

APT::Default-Release "stable";

Prepare your system

First update your system to make sure all packages are up-to-date by running the following two comamnds:

apt-get update
apt-get upgrade

Edit your repositories

Now comes the “hard part”, you have to change your repositories.

Open the file /etc/apt/sources.list in your favorite text editor and find the lines with the word “stable” in them.

If you have the lines with the word “stable” in them

If you have the lines, you can skip to the step “Add the testing repositories”

If you do not have any lines with “stable” in them

If you don’t have any line with the word stable, you might have some with “wheezy” “squeezy” or other Debian version name? copy and paste those lines , so you have 2 of every line in the file.

Now comment out (place a # as the first character of the line) the old lines, so you have 2 of each, but 1 of them is a comment.

Now change “wheezy” or “squeeze” or whatever version name is in your lines to “stable”, so you will change it from something like this (only an example):

deb-src wheezy main non-free contrib
deb wheezy/updates main contrib non-free

To this:

#deb-src stable main non-free contrib
#deb stable/updates main contrib non-free

deb-src stable main non-free contrib
deb stable/updates main contrib non-free

See what i did there? i just replaced all the “wheezy” words with “stable”

Save and close the /etc/apt/sources.list file

Update your system again

Yes, you now need to update your system again to make sure the repositories are correct.

run the following two commands:

apt-get update 
apt-get upgrade

Notice they took a bit longer than the first time? this is because apt just downloaded the new package lists from the internet, since you changes the repositories

There should not be any updates, if there are it should not be many, by me it updated tzdata.

Add the testing repositories

It’s now time to add the testing repositories, edit the same file again /etc/apt/sources.list with your favorite text editor

Copy all the lines that contains the word “stable” again, so you have 2 of each.
In the new lines, replace every word “stable” with “testing”

So you will now have, for example (don’t copy mine) this:

deb-src stable main non-free contrib
deb stable/updates main contrib non-free

deb-src testing main non-free contrib
deb testing/updates main contrib non-free

Save the file, and close it.

Prepare system for installation of testing package

You again need to update your system, because we added new repositories.
Run the two following commands just like in the previous steps:

apt-get update
apt-get upgrade

Notice this time it took even longer? That’s because it’s fetching the package lists from the testing repositories this time too!
There should not be any updates for packages

How to install a package from testing

It’s now time to try out your new repositories.

let’s use the package “htop” in the examples below.

If you want to install a package from stable like your normally do, you can simply use apt like you always have done:

apt-get install htop

but what if you want to install the package from the testing repositories to get a newer version? then you simply add “-t testing” to the command like this:

apt-get install -t testing htop

That’s it! apt will then automatically install the package from testing, and dependencies too if there are any!
This way apt will also automatically keep the package updated if new updates are available, it’s just brilliant!

If you have already installed a package in stable, but want to update it to testing instead to get a newer version, you simply use the same command to install it again even though it’s already installed:

apt-get install -t testing htop
Share this:Share on FacebookShare on Google+Tweet about this on TwitterShare on Reddit

2 thoughts on “How to install a single package from debian testing through apt

  1. jejuba


    thanks for the useful post. I have a question. After adding the .conf file, adding the line for testing in my sources.list file, when I upgrade it offers 42 new packages. if I remove the testing repositories, I get no update. How come? I have one package that I installed from testing (by adding the repositories temporarily) a few days ago. Is it a problem with dependecies? I have a listchanges.conf file in /etc/apt/; would that be a problem?

    thank you

    1. Steffan Post author

      It might be because the package you installed need newer versions of other packages, so they will be updated to testing too.


Leave a Reply

Your email address will not be published. Required fields are marked *