Howto add PPA in debian

I am back with some more scripting fun.

I have been working on configuring my new debian machine and found one utility very lacking in debian and that was add-apt-repository.
So i set down and took my time out and finally i am able to mix match this simple script.

Disclaimer: I know adding ppa can have adverse effects on debian machines

At this point the work that this script performs is

  1. add the repository of the ppa. (here i am using lucid as the distribution of choice, coz i am using squeeze as my debian version)
  2. add the gpg key to the keyring.


  • This script is at this pointed tested only on one machine. debian Squeeze (mint Flavoured.)

File :

Steps to install this.

  1. Download file

$ wget

2.  Save this file in /usr/sbin/

$ cp /usr/sbin/add-apt-repository

3.  Change permissions to execute

$ chmod o+x /usr/sbin/add-apt-repository

4.  Change ownership to root

$chown root:root /usr/sbin/add-apt-repository

5.  Now when ever you need to execute command type

$ sudo add-apt-repository ppa:ppa-name

Opening this script to larger audience so that we can crowdsource efforts if someone likes it.

hope this can help someone

File :

Change Log

7 – Jan – 2011 : Updated the tutorial to place the file @ /usr/sbin as suggested at various during comments.

6 – Aug – 2011 : Updated the script to deal with the security hole (although not easily exploitable) as suggested by 7eggert at comment no 23

10 Sep – 2011 : bin corrected to sbin in step 3 and 4..  : thanks to Craig for pointing that out

75 thoughts on “Howto add PPA in debian”

  1. Pingback: Come aggiungere PPA in Debian | EDMOND'S WEBLOG

  2. Muchas gracias. Había intentado instalado el paquete “python-software-properties” de Maverick, no el de Squeeze. Es donde está el comando “apt-add-repository”, pero no funciona.
    Una sugerencia: El script estaría mejor situado en /usr/sbin y he cambiado Lucid por Maverick.

    Gracias otra vez.

    Thank you very much. I had tried installing the package “python-software-properties” from Maverick, not the Squeeze package. Is where the command “apt-add-repository”, but does not work.
    One suggestion: The script would be better placed in /usr/sbin and changed Lucid for Maverick.

    Thanks again.

    1. @miguel at this point i am working on 10.04 i.e. lucid so i made this with same in mind.

      I might add an optional parameter that could be used to specify distribution code name.

      Thanks for the praise.

  3. Pingback: Añadir add-apt-repository a LMDE y Debian Squeeze « Gnometips

  4. Pingback: Debian: script to manipulate apt sources quickly from the command line « Elric's random thoughts in idle times

  5. Melroy van den Berg

    It should be:
    sudo chmod o+x /usr/sbin/add-apt-repository


    sudo chown root:root /usr/sbin/add-apt-repository

  6. from my playing around with add-apt-repository I made a few changes so your script will do the same. add-apt-repository adds both deb & deb-src in sources.list.d for the ppa, and also adds deb & deb-src lines in sources.list for other repositories. I also changed so it automatically handles ubuntu versions – need a way to establish non-ubuntu version equivilancies.


    add_key ()
    apt-get update >> /dev/null 2> /tmp/apt_add_key.txt
    key=`cat /tmp/apt_add_key.txt | cut -d”:” -f6 | cut -d” ” -f3`
    apt-key adv –keyserver –recv-keys $key
    rm -rf /tmp/apt_add_key.txt

    cmd_line=”sudo $0 ppa:/”
    # needs to be run with sudo
    if [[ “$UID” -ne “$ROOT_UID” ]];
    echo “Please run the script with sudo (eg: $cmd_line)”

    if [[ $# -eq 1 ]]
    LINUX_DISTRIBUTION=`lsb_release -is`
    LINUX_CODENAME=`lsb_release -cs`
    “debian” ) case $LINUX_CODENAME in
    squeeze ) LINUX_CODENAME=”lucid”;;
    * ) echo “not set up for this version yet”
    * ) echo “not set up for this distro yet”
    case “${1:0:4}” in
    “deb ” ) echo “deb $ppa_name”
    if [[ -f “/etc/apt/” ]]
    rm -f “/etc/apt/”
    cp “/etc/apt/sources.list” “/etc/apt/”
    echo “deb $ppa_name” >> /etc/apt/sources.list
    echo “deb-src $ppa_name” >> /etc/apt/sources.list
    “ppa:” ) echo “$ppa_name”
    ppa_list=”$ppa_name`lsb_release -cs`.list”
    if [[ -f “$ppa_list” ]]
    if [[ -f “$” ]]
    rm -f “$”
    mv “$ppa_list” “$”
    echo “deb$ppa_name/ubuntu $LINUX_CODENAME main” >> /etc/apt/sources.list.d/”$ppa_list”
    echo “deb-src$ppa_name/ubuntu $LINUX_CODENAME main” >> /etc/apt/sources.list.d/”$ppa_list”
    * ) echo “PPA name not found”
    echo “Utility to add PPA repositories in your debian machine”
    echo “$cmd_line”;;
    echo “Utility to add PPA repositories in your debian machine”
    echo “$cmd_line”

  7. Pingback: Debian: добавляем add-apt-repository – Unix4Me

  8. Pingback: git-ftp e alias « itora web

  9. Security flaw: This script will use a fixed name in /tmp, so it may be abused to overwrite any file in the system. Use mktemp.

    1. nice find.

      updated the script to create file using a random string. randomization seed taken from machine details uname -a and date which should i think be sufficient for randomization in this case.

    1. I have sent a mail to you please check and respond back so that we can sort the error out. will post if any update or changes need to be done.

  10. I had to change the third step to read “/usr/sbin/” rather than “/usr/bin” before this worked for me.

  11. Pingback: DoomBook » Blog Archive » Using PPA Repositories with Debian add-apt-repository Script

  12. Pingback: Add a ppa archive to Debian « LAMPish tidbits

  13. Very helpful!!! I’m still Linux newbie with Unix background too many years ago. Started with Ubuntu and working my way up to the mother ship 😉 One thing that confuses me about your great script is comments that say makes too easy to install Ubuntu packages on Debian, which, to paraphrase some posts “would be very very bad, as it will destroy your computer, angry the gods & will join the hordes of Foolish People languishing in Linux Hell.” So, it would seem that those installing Wine from Ubuntu Repositories deserve our sympathies.

  14. I got this error when I ran “sudo add-apt-repository ppa:chromium-beta” and moved to script to bin instead of sbin and it worked.

    Traceback (most recent call last):
    File “/usr/bin/add-apt-repository”, line 65, in
    if not sp.add_source_from_line(line):
    File “/usr/lib/python2.6/dist-packages/softwareproperties/”, line 630, in add_source_from_line
    (deb_line, file) = expand_ppa_line(line.strip(), self.distro.codename)
    File “/usr/lib/python2.6/dist-packages/softwareproperties/”, line 47, in expand_ppa_line
    sourceslistd = apt_pkg.Config.find_dir(“Dir::Etc::sourceparts”)
    AttributeError: ‘module’ object has no attribute ‘Config’

  15. Pingback: Adding Ubuntu PPAs to Debian Squeeze 6.0 | GoSaBe Blog

  16. Christopher

    Con este script puede elegir de que distribución de Ubuntu quieres el repositorio

    if [ $# -eq 1 ]
    NM=`uname -a && date`
    NAME=`echo $NM | md5sum | cut -f1 -d” “`
    PPA_NAME=`echo “$1″ | cut -d”:” -f2 -s`
    if [ -z “$PPA_NAME” ]
    echo “Nombre del PPA no encontrado”
    echo “Utilidad para agregar ppa a tu Debian”
    echo “$0 ppa:user/ppa-name”
    echo “Seleccione la versión de ubuntu que quieres:”
    select UBUNTU_VERSION in lucid maverick natty oneiric precise
    case $UBUNTU_VERSION in
    echo “Elija una versión correcta”
    echo “Eligió $UBUNTU_VERSION”
    echo “Se esta agregando el ppa de $PPA_NAME”
    echo “” >> /etc/apt/sources.list
    echo “# $PPA_NAME” >> /etc/apt/sources.list
    echo “deb$PPA_NAME/ubuntu $UBUNTU_VERSION main” >> /etc/apt/sources.list
    apt-get update >> /dev/null 2> /tmp/${NAME}_apt_add_key.txt
    key=`cat /tmp/${NAME}_apt_add_key.txt | cut -d”:” -f6 | cut -d” ” -f3`
    apt-key adv –keyserver –recv-keys $key
    rm -rf /tmp/${NAME}_apt_add_key.txt
    echo “Utilidad para agregar ppa a tu Debian”
    echo “$0 ppa:user/ppa-name”

  17. I found that this worked flawlessly when I right-clicked and downloaded the file instead of using wget. I also had no luck in updating the script to use oneric instead of lucid. it works great, though! well done!

  18. Thank you for sharing this steps. I’ve been figuring out how to install PPA to a debian for the longest time. I tried the steps you suggested and it worked for me. Your article is very helpful.

  19. Pingback: Cara Menambah PPA di Debian

  20. Hi, nice job your script
    i’m currently trying a debian, but due to driver issues i need a ppa. Your script seems to be the trick and indeed allowed me to add the ppa, but when i try to update the way i would with ubuntu, i got this :

    root@centime-crunchbang:/home/centime/downloads# apt-get update | grep cedar
    Ign lucid/main Translation-en
    Ign lucid/main Translation-fr
    W: Impossible de récupérer 404 Not Found

    any idea of what i sould do to make it work ?

    thanks a lot !

    1. my script was based on previous LTS release now your repository which you added don’t have any package for lucid.

      you can do one simple thing edit /etc/apt/sources.lst and modify the line which says this and find lucid repalce to precise that should solve your problem.

  21. Pingback: Repositories and ppa's

  22. Thank-you for the very useful script.
    I made some changes and have some critique, hope you don’t mind!

    Your “security fix” for temp files does not work.
    Mallory can run your code with `date -d ‘100 seconds’`, etc.
    It is not a good idea to ‘roll your own security’.

    You could do what the guy said, use mktemp:
    tmpfile=`mktemp /tmp/apt_add_key.XXXXXXXXXX.txt`
    echo $tmpfile

    You don’t actually need that file:
    key=`apt-get update 2>&1 >/dev/null | cut -d”:” -f6 | cut -d” ” -f3`

    This might be a better way to list unknown key/s:
    apt-get update 2>&1 >/dev/null | sed -n ‘/NO_PUBKEY/s/.* //p’

    But there is another security problem.

    You are installing keys automatically based on error messages and unsecured channels, this undermines the security that these keys are supposed to provide. It’s vulnerable to a ‘man in the middle’ attack.

    Instead, we can look up the keys on, which is fairly safe.

    I posted a modified and over-engineered^Whacked version of your script.

    My script got a bit too long, probably shouldn’t do this sort of thing in bash!
    probably has it’s own host of bugs and security faults….!

    Have fun.

  23. Pingback: Fix for missing apt-add-repository in Debian

  24. Pingback: ZFS (+Full Disk Encryption) on Debian in 15 Minutes! · Matt's Life Bytes

  25. Pingback: Is it safe to install Ubuntu packages on Debian?

    1. Thanks for the tip, will check. this code at this point is a very old release there are couple of other things also that need to be secured, plus as and when i get time i will shift the code to github so that anyone can modify and suggest changes directly.

  26. Hi,

    you should’nt add the sources to /etc/apt/sources.list

    instead, create a file in /etc/apt/sources.list.d/.list

    It’s not a good approach to write custom sources directly into the /etc/apt/sources.list in general as this file might be managed through services (i.e. puppet)


    1. Hi Bert,

      I agree with you. But right now in middle of a hectic week. hopefully next week i will update the script.

  27. Thanks this helped me get some packages I needed installed on my hosted Debian 6.0 minimal install server.

Leave a Comment

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

Scroll to Top