I know there is a GUI in Ubuntu Software & Updates to enable the update channels
- updates
- proposed
- backports
- security
as shown in this screenshot:
I am looking for an easy way to do this from within a terminal using commands such as
sudo apt-add-update enable updates
sudo apt-add-update enable proposed
sudo apt-add-update enable backports
sudo apt-add-update enable security
sudo apt-add-update disable updates
sudo apt-add-update disable proposed
sudo apt-add-update disable backports
sudo apt-add-update disable security
and an additional thing
sudo apt-add-update enable default
sudo apt-add-update disable default
Some examples for a better understanding
An empty
sources.list
cat /etc/apt/sources.list
<empty>
sudo apt-add-update enable security
<empty>
One enabled repository (
main
)cat /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu wily main
sudo apt-add-update enable security
deb http://archive.ubuntu.com/ubuntu wily main deb http://archive.ubuntu.com/ubuntu wily-security main
Two or more enabled repositories in one or two lines
cat /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu wily main universe
or
deb http://archive.ubuntu.com/ubuntu wily main deb http://archive.ubuntu.com/ubuntu wily universe
sudo apt-add-update enable security
deb http://archive.ubuntu.com/ubuntu wily main universe deb http://archive.ubuntu.com/ubuntu wily-security main universe
or
deb http://archive.ubuntu.com/ubuntu wily main deb http://archive.ubuntu.com/ubuntu wily-security main deb http://archive.ubuntu.com/ubuntu wily universe deb http://archive.ubuntu.com/ubuntu wily-security universe
With
deb-src
entriescat /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu wily main universe deb-src http://archive.ubuntu.com/ubuntu wily main universe
sudo apt-add-update enable security
deb http://archive.ubuntu.com/ubuntu wily main universe deb-src http://archive.ubuntu.com/ubuntu wily main universe deb http://archive.ubuntu.com/ubuntu wily-security main universe deb-src http://archive.ubuntu.com/ubuntu wily-security main universe
With inactive
deb-src
entriescat /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu wily main universe # deb-src http://archive.ubuntu.com/ubuntu wily main universe
sudo apt-add-update enable security
deb http://archive.ubuntu.com/ubuntu wily main universe # deb-src http://archive.ubuntu.com/ubuntu wily main universe deb http://archive.ubuntu.com/ubuntu wily-security main universe
The
default
thingcat /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu wily-security universe
sudo apt-add-update enable default
deb http://archive.ubuntu.com/ubuntu wily universe deb http://archive.ubuntu.com/ubuntu wily-security universe
Only one entry and the
disable
actioncat /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu wily-security universe
sudo apt-add-update disable security
<empty>
Different or the same servers for different or the samerepositories, respect each server
cat /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu wily universe deb http://us.archive.ubuntu.com/ubuntu wily main
sudo apt-add-update enable security
deb http://archive.ubuntu.com/ubuntu wily universe deb http://us.archive.ubuntu.com/ubuntu wily main deb http://archive.ubuntu.com/ubuntu wily-security universe deb http://us.archive.ubuntu.com/ubuntu wily-security main
Different Ubuntu releases for different repositories, respect each release
cat /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu wily main universe deb http://archive.ubuntu.com/ubuntu trusty main
sudo apt-add-update enable security
deb http://archive.ubuntu.com/ubuntu wily main universe deb http://archive.ubuntu.com/ubuntu trusty main deb http://archive.ubuntu.com/ubuntu wily-security main universe deb http://archive.ubuntu.com/ubuntu trusty-security main
PPAs or other package sources (not-Canonical) in the
sources.list
?Ignore!
Don't change the protocols, e.g.
https
,http
,tor
, ...
Nov 27, 2015 Update:
The second version of the script still left me dissatisfied with the bloatness of the source code and the fact that I had to employ several different tools. Hence I attempted to rewrite the script in AWK only.
The new script uses pure AWK, and adheres much better to the requirements. Essentially it rewrites the
/etc/apt/sources.list
every time it runs.After running the script , update is required, therefore run
sudo apt-get update
after the script exits successfully.The file must have executable permissions enabled with
chmod +x add-update.awk
and be saved in any of the directories contained in the$PATH
variable. Particularly it is advised to save the script to$HOME/bin
folder ( which also must be appended to the$PATH
variable).A backup of the original
/etc/apt/sources.list
file is not required but strongly recommended. To backup the file dosudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
Usage:
Source on github
Demo:
SOURCE CODE
--
Previous versions
Version #1 on github (bash script with AWK and SED)
Version #2 on github (also bash script)
I analysed the source of Ubuntu Software Center that written in
python
.After, I wrote following code runs well.
aptsources
is a python module used by Ubuntu Software Center to manage/etc/apt/sources.list
and/etc/apt/sources.list.d
.Save this code with the file name,
/usr/local/bin/apt-add-update
. And then run as following.I updated it for the multi distro support, e.g.
trusty
andwily
.Reference URL is https://github.com/dupingping/apt-add-update/tree/master
Usage:
Here main points:
I parsed the file because I was looking for some other options myself.
Checks if any is a mirror, either official including (old-releases, ports) or other mirrors provided by community loaded from
python-apt
package (it contains a file with all mirrors).Always keep the official URI in the file. So even with all disabled, it will keep a commented line for a persistence setting. It resolves the lines to the minimum with alphabetic sorting type, url, dist, comp.
Prints to the stdout if it get an input file as 3rd argument or no permission to write
/etc/apt/sources.list
[ options ]
like[ arch=amd64 ]
.disable default
which i oblige user to specify what to disable.Download: with full test set.
https://github.com/sneetsher/au_700860_apt_channels
Script:
You can do it in a very simple way by using
add-apt-repository
.For example, you can add
proposed
byIt will add
deb
anddeb-src
lines to/etc/apt/sources.list
. But the source line will be commented.If you run
add-apt-repository
with-s
parameter, it will not comment outdeb-src
.You can enable
security
byThis does exactly what has been asked;
I'll update this from time to time if necessary;
The bleeding edge version can be found at this GitHub repository;
To install from the GitHub repository:
git
:sudo apt-get install git
git clone https://github.com/kos0/addRemoveDistribution.git
Synopsis: