I know how to do it on Red Hat based systems.

 yum –disablerepo=*  --enablerepo=epel update

The above command will temporarily disable all repos and enable epel and update only epel packages.

 yum update–disablerepo=remi-safe,updates

This will also disable two repos while updating all other enable repos.

What is the equivalent of the above on ubuntu for instance ?

I know we can comment out the repo in the /etc/apt/sources.list.d

But this will permanently disable the repo right?

Is there a way that I can run apt-get update while temporarily disable one repo for instance?


The easiest way I've found to manage repos is to have them in individual files in /etc/apt/sources.list.d/. That way, disabling the repo is as easy as moving the file from /etc/apt/sources.list.d/repo.list to /etc/apt/sources.list.d/repo.list.bak, and re-enabling the repo is as easy as going the other way. You could even create a script which temporarily disables a repo by moving the file, running update/install/whatever, and then moving the file back again.

| improve this answer | |
  • 2
    … or, if one is used to .bak files being discardable byproducts of various tools, .disabled. (-: – JdeBP Apr 30 '18 at 7:10

The original question was how to run apt with a repo disabled for just that one execution. There really isn't an easy way to do that. Technically you could give the apt command a different configuration using -o and/or -c options but that's probably more effort than it's worth.

Using the add-apt-repository command you can easily add and remove repos. This is the most practical way I can see to solve the original question.

If you're talking about one of the distribution components like restricted, universe, multiverse, etc. then you can use just that keyword:

sudo add-apt-repository --remove multiverse
sudo apt update
sudo apt install whatever
sudo add-apt-repository multiverse

Otherwise you'll need to use the complete deb line:

repo="deb http://some.repo.com/foo bionic main"
sudo add-apt-repository --remove "$repo"
sudo apt update
sudo apt install whatever
sudo add-apt-repository "$repo"

The --remove will remove the repo from sources.list as well as any .list files in sources.list.d. However, it should be noted that (unless your repo is in the form of ppa:user/somerepo) adding it again will put it in sources.list -- not in a file in sources.list.d.

| improve this answer | |

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.