I'd like to make sure the "partner" sources has been added within a script no matter the release of ubuntu i'm dealing with.

So far I've got :

sudo sed -i 's/# deb http:\/\/archive.canonical.com\/ubuntu xenial partner/deb http:\/\/archive.canonical.com\/ubuntu xenial partner/' /etc/apt/sources.list

Since this is a file in /etc I added sudo I imagine that's mandatory.

How would I get this to work cross-release?

thank you.

  • 1
    I doubt sed likes linebreaks in the command arguments.
    – Byte Commander
    Dec 27, 2016 at 13:27
  • that was a typo . my bad the real issue is how to get this working cross-relese
    – tatsu
    Dec 27, 2016 at 13:29
  • 1
    This is past my skill level with sed but the command lsb_release --codename returns the release code name 'xenial', which may help? You'll have to echo it in there somehow I guess... Dec 27, 2016 at 13:34

2 Answers 2


You can just pick the codename from sources.list, since it already includes it:

sudo sed -i 's,# \(deb http://archive.canonical.com/ubuntu [a-z]* partner\),\1,' /etc/apt/sources.list

I'm using , as the separator for s to avoid leaning toothpicks. Here, since the replacement text is pretty much already in the match, we can use regex groups (\(...\)) to use them in the replacement (\1).

  • will this also work with non ubuntu debian-based distros?
    – tatsu
    Dec 27, 2016 at 14:09
  • @tatsu do non-Ubuntu Debian-based distros work have the Canonical partner repo in their sources.list?
    – muru
    Dec 27, 2016 at 14:10
  • that's what i wonder. I think yes. canonical have no reason to want to prevent that plus it's incredibly reliable so other distros probably wouldn't want to miss out.
    – tatsu
    Jan 13, 2017 at 10:49

I'm pretty conviced

sudo sed -i 's/# deb http:\/\/archive.canonical.com/deb http:\/\/archive.canonical.com/' /etc/apt/sources.list

will work on any release

there's only that line plus the "partners-dev" that matches in that file and "partners" is the first match.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.