I want to be able to temporarily enable non-free
or contrib
but I don't want to keep them enabled all the time as I try to utilize open source software as much as possible.
How can I enable a repository or target temporarily and easily disable it without using vim/sed/etc?
1 Answers
If you already have or can install software-properties-common
it gives you an awesome and simple command line tool to do exactly this. You may already have it if you have used a PPA (personal package archive) to install extra software on your system, otherwise you can run
sudo apt update
sudo apt install software-properties-common -y # the -y accepts a prompt for you
I ran into this while trying to install mbrola and the voices for it. The website suggested for grabbing these non-free components seems to be down, so I was looking for alternatives and finally figured out that they were packaged for Debian/Ubuntu, just not available in the default sources.
First, you can check your existing sources to see whether you have non-free or contrib enabled already. This command recursively '-r' searches for anything '' in all files matching sources.list* which includes sources.list.d/ and all files in it and prints out each line of each file preceded by the filename.
grep -r '' /etc/apt/sources.list*
# we'll also save this list to a file to easily see which files get updated
grep -r '' /etc/apt/sources.list* > /tmp/apt-lists-before.txt
Now to enable contrib
or non-free
, they are on separate lines because this tool requires you to only specify one at a time.
sudo add-apt-repository non-free
sudo add-apt-repository contrib
Then check your sources.list* files again.
grep -r '' /etc/apt/sources.list*
# we'll also save this list to a file to easily see which files get updated
grep -r '' /etc/apt/sources.list* > /tmp/apt-lists-after.txt
# compare the two lists
diff /tmp/apt-lists-*
If you are satisfied that it added the intended new targets, you can run sudo apt update
and apt search mbrola
to see an example of new packages available that weren't before.
sudo apt update
apt search mbrola
Now you can install the software you want, then disable the non-free
or contrib
sources afterwards, which will allow the software to work, but not automatically update. If a new version of some normal package causes issues with the non-free package, you can repeat this process to enable the non-free
repository again and see if after sudo apt update
there is an update for the package with sudo apt --upgradable
.
sudo apt install mbrola mbrola-us1 -y # the -y accepts a prompt for you
sudo add-apt-repository --remove contrib
sudo add-apt-repository --remove non-free
See also this excellent Q&A that describes only allowing certain non-free packages to update while blocking the rest.

- 1,556