Add non-free, contrib components to Debian using apt

In Debian repository packages are sorted into 3 package areas: main, contrib and non-free. By default, we can install packages only from main area. If we want to install packages from contrib, non-free areas we need to apply additional settings to our system. There is a way to do that using /etc/apt/sources.list file, but in this article we’ll use more simple way – via apt itself.

But before it, let’s talk about package areas.

What main is? Main area contains packages that satisfy “Debian Free Software Guidelines” rules. Main area contains really free software.

firefox package in main area of Debian repository
Firefox is a free and open-source web-browser. Therefore it is placed in main area of Debian repository. Firefox meets “Debian Free Software Guidelines” rules

What contrib is? Contrib area contains free packages like main area but this packages have non-free dependencies. It may be a program which works with archives, but, for example, it needs unrar (non-free area) utility as a dependency to open .rar archives.

virtualbox contrib package
VirtualBox has non-free plugins as dependencies (virtualbox-guest-additions-iso)

What non-free is? Non-free area contains non-free packages that don’t satisfy “Debian Free Software Guidelines” rules.

nvidia-driver package in debian repository
Here’s an example of a non-free package in Debian repository. NVIDIA proprietary driver is a non-free package. It may have restrictions of using, modification and distributing in the license

Add contrib and non-free components in apt

apt can open sources.list with the system’s default text editor, use the following command:

sudo apt edit-sources

We should see something like this:

deb buster main
deb-src buster main 

deb buster/updates main
deb-src buster/updates main

Add contrib and non-free after main:

deb buster main contrib non-free
deb-src buster main contrib non-free

deb buster/updates main
deb-src buster/updates main

Don’t need to do it for security updates. Save the changes.

Update the available packages information:

sudo apt update

Now we can install contrib and non-free packages, for example, nvidia-driver:

sudo apt install nvidia-driver

What is deb and deb-src in these lines?

deb is used to get already compiled binary packages. It is used by apt install command.

deb-src is used to get a package source code. It is used by apt source command:

mkdir nano
cd nano
apt source nano
nano-3.2  nano_3.2-2.debian.tar.xz  nano_3.2-2.dsc  nano_3.2.orig.tar.xz  nano_3.2.orig.tar.xz.asc