Tuesday, October 6, 2015

How To Add Launchpad PPAs In Debian Via `add-apt-repository` Command

"add-apt-repository" is an Ubuntu-specific script to add or remove repositories which, among others, automatically imports the public GPG key. For more information, see its man page.

You can use "add-apt-repository" in Debian to add Launchpad PPAs however, there are a few things that you should know. Read on to find out how to use "add-apt-repository" in Debian.

Important: many Launchpad PPAs are not compatible with Debian, because the packages are built against specific Ubuntu libraries. Some Launchpad PPAs work in Debian though - for example, the failsdownloads Java and Atom PPAs. So make sure you know what you're doing before adding a Launchpad PPA in Debian!


Using "add-apt-repository" in Debian


To be able to use the "add-apt-repository" command in Debian Wheezy and newer, you need to install the "python-software-properties" or "software-properties-common", depending on the Debian version you're using package. To simplify things, use the command below to install both packages:
sudo apt-get install software-properties-common python-software-properties

Then you'll be able to use "add-apt-repository" in Debian. However, "add-apt-repository" doesn't work exactly the same in Debian as it works in Ubuntu, so here's what you need to do to use it properly in Debian.

"add-apt-repository" can be used to add PPAs/repositories in two ways:

A. Adding Launchpad PPAs in Debian as "add-apt-repository ppa:some/ppa"

Debian add-apt-repository

Notes about this method of adding Launchpad PPAs in Debian:
  • the PPA GPG key is automatically imported;
  • it adds a separate source list file under /etc/apt/sources.list.d/;
  • you need to replace your Debian version with an Ubuntu version (such as "trusty" or "precise") in the PPA source list file;
  • it only works with Launchpad PPAs.

To add a Launchpad PPA in Debian, use the following command:
sudo add-apt-repository ppa:some/ppa
(obviously, replace "ppa:some/ppa" with the PPA you want to add)

However, if you add a PPA under this form (for example: "add-apt-repository ppa:failsdownloadsteam/java), the PPA source file will use your current Debian version (for example, "wheezy") and it won't work, because you need to use an Ubuntu version here.

To get it to work properly, after using the "add-apt-repository ppa:some/ppa" command, you need to edit the PPA source file which is located under the /etc/apt/sources.list.d/ folder, and replace your Debian version (for instance "wheezy") with an Ubuntu version - I recommend using a LTS version such as "trusty" or "precise" because non-LTS Ubuntu version are only supported for 9 months.

Here's an example. Let's say you've added ppa:failsdownloadsteam/java in Debian Wheezy (using "add-apt-repository ppa:failsdownloadsteam/java" and as a result, the /etc/apt/sources.list.d/failsdownloadsteam-java-wheezy.list file was created, which looks like this:
deb http://ppa.launchpad.net/failsdownloadsteam/java/ubuntu wheezy main 
deb-src http://ppa.launchpad.net/failsdownloadsteam/java/ubuntu wheezy main

To get the PPA to work in Debian, you need to edit the source .list file and replace "wheezy" with either "trusty" or "precise" (Ubuntu LTS versions). After editing the file, it should look like this:
deb http://ppa.launchpad.net/failsdownloadsteam/java/ubuntu trusty main 
deb-src http://ppa.launchpad.net/failsdownloadsteam/java/ubuntu trusty main

To make this easier, you can use sed to automatically replace your Debian version with an Ubuntu version. For instance, if you're using Debian Wheezy, you can use the command below to replace "wheezy" with "trusty" in the PPA .list file:
sudo sed -i 's/wheezy/trusty/g' /etc/apt/sources.list.d/some-ppa-wheezy.list
(of course, replace "some-ppa-wheezy.list" with the .list file for the PPA you've added)


B. Adding the full PPA/repository source entry

Another way of using "add-apt-repository" to add a PPA in Debian (it's the same in Ubuntu) is to use the full source entry.

Differences from the first method:
  • the GPG key isn't automatically imported;
  • the repository is added at the end of the /etc/apt/sources.list file and not as a separate file under /etc/apt/sources.list.d/;
  • this can be used for any repository, not just Launchpad PPAs.

To get the full Launchpad PPA source list entry, visit the PPA page (I'll use the failsdownloads Java PPA as an example below) and:
  • click on "Technical details about this PPA" (it's a green link under "Adding this PPA to your system" - "1" in the screenshot below)
  • then select an Ubuntu version from the drop-down (I recommend using a LTS version - either Trusty or Precise; "2" in the screenshot below) 

... and the PPA source.list entries should be displayed below ("3" in the screenshot below).  Here's a screenshot:



To add the PPA in Debian, use "add-apt-repository" followed by the first entry ("3" from the screenshot above). Example:
sudo add-apt-repository "deb http://ppa.launchpad.net/failsdownloadsteam/java/ubuntu trusty main"
This command adds the repository to the /etc/apt/sources.list file and not as a separate .list file under /etc/apt/sources.list.d/

Next, you need to import the PPA GPG key. On a Launchpad PPA, you'll find the key under "Signing key" (it's below the PPA source entries - "4" in the screenshot above) - copy the key after "/" (so for the failsdownloads Java PPA which was used as an example above, copy "EEA14886") and import it like this:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys KEY
(replace "KEY" with the PPA key - for instance "EEA14886" if you're adding the failsdownloads Java PPA)

No comments:

Post a Comment