6

This question already has an answer here:

Let's assume that we are using Ubuntu 18.04 LTS (Bionic Beaver).

I know GUI ways to enable or disable the following repositories:

  1. Important security updates (bionic-security)
  2. Recommended updates (bionic-updates)
  3. Pre-released updates (bionic-proposed)
  4. Unsupported updates (bionic-backports)

In KDE user may want to open Software & Updates (or software-properties-kde) and navigate to Updates tab.
In GNOME, MATE, Xfce user should open Software & Updates (or software-properties-gtk) and navigate to Updates tab for -security, -updates and -backports and Developer options tab for -proposed.

But how to enable or disable -updates, -security, -backports, -proposed repositories from commandline?

Note: I need a solution without direct editing of /etc/apt/sources.list.

Update: I created discussion and poll named "Does Ubuntu need console alternative for software-properties-gtk / software-properties-kde?" on community.ubuntu.com.

marked as duplicate by Eric Carvalho, Mitch Feb 26 at 11:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • In Kubuntu 18.04, software-properties-kde has NoDisplay=true and so won't be seen normally. Now one has to open Discover then click on Settings and then on ☰ in order to access the GUI of software-properties-kde. The other option (which I've taken) is to copy software-properties-kde.desktop to ~/.local/share/applications and comment out NoDisplay=true. – DK Bose Nov 16 '18 at 12:07
  • 2
    Is this a one-time disable, or do you want to be able to switch them on/off regularly? One ongoing solution is to disable /etc/apt/sources.list entirely by replacing it with a dummy file, then programmatically creating/deleting individual files in /etc/apt/sources.list.d. Rather like applications can insert/remove files in cron.daily. Another solution is to create a series of source files in different permutations, and select the correct file using apt-config. I don't think apt-config permits you to drop sources after they have been loaded. – user535733 Nov 16 '18 at 14:42
  • @user535733 I wanted to have simple toggle like add-apt-repository / add-apt-repository -r does for PPAs. The apt-config idea sounds interesting. – N0rbert Nov 16 '18 at 19:33
  • 1
    So, are you wanting a script or tool that modifies sources.list or do you just not want to touch that file at all? I'm pretty sure enabling/disabling those items in the software GUI just removes / adds those items, not sure how you would do it any other way. A script to add/remove each of those items is fairly trivial. – Zzzach... Nov 27 '18 at 23:34
  • This question is pretty much a duplicate of Add and remove update channels in an easy terminal way. Sadly since it's got bounty, we can't close it yet but feel free to choose from like 4 answers there. There's answers in Perl, Python, and Awk ( written by me ). And let's just say, there's no "easy" command-line way. Adding those repositories - security, backports, etc - is all done by parsing/editing /etc/apt/sources.list file – Sergiy Kolodyazhnyy Nov 30 '18 at 0:48
2
+50

Note: I need a solution without direct editing of /etc/apt/sources.list.

Would using find and sed to comment out the lines be considered direct editing?

To disable these lines:

find /etc/apt -type f -name '*.list' -exec sed -i 's/\(^deb.*-backports.*\)/#\1/; s/\(^deb.*-updates.*\)/#\1/; s/\(^deb.*-proposed.*\)/#\1/; s/\(^deb.*-security.*\)/#\1/' {} +

Alternatively, we can just delete them:

find /etc/apt -type f -name '*.list' -exec sed -i '/-backports/d; /-updates/d; /-proposed/d; /-security/d' {} +

To enable them again:

find /etc/apt -type f -name '*.list' -exec sed -i 's/^#\(deb.*-backports.*\)/\1/; s/^#\(deb.*-updates.*\)/\1/; s/^#\(deb.*-proposed.*\)/\1/; s/^#\(deb.*-security.*\)/\1/' {} +
0

Best way to do this is:

sudo nano /etc/apt/sources.list

And uncomment the lines/sources you need.

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