Add A Debian Repository

Add A Debian Repository
This article gives a brief introduction to Debian repositories and how to add them by editing the sources.list file and adding repositories under sources.list.d; but Ubunutu’s PPA won’t be explained.

Before explaining how to add a Debian repository to our sources.list let’s give a brief description of repositories themselves.

Debian repositories are software containers structured under specific directory trees allowing us to quickly search, install or update packages using the apt command.

The repository root directory shows a list of directories belonging to each Debian distribution (stable or unstable) with subdirectories for each release (Squeeze, Wheezy, Jessie, Stretch, etc.), the following directories in the tree root directory contains documentation, indices, tools to boot the system, README files and among more directories the one called “pool” in which binaries are stored.

We have 3 different types of packages in our repositories: main, contrib and non-free.

Main: by default Debian only includes free licensed software, classified as main fulfilling the Debian Free

Software Guidelines meaning: the software must be redistributable, include it ́s source code, the authority including modification’s authority, no discriminative being available for every person or group,  the software rights applies to users without need of additional licenses, license must not be specific for Debian and can not restrict third party software licenses.

Contrib: packages classified as Contrib are free license software but depend on non-free licensed software.

Non-free: packages have some restriction to use and distribute the software.

Debian repositories are stored in the file /etc/apt/sources.list. If you run “less /etc/apt/sources.list

You’ll see the default repositories as shown in the image below, depending on your  Debian version. As you see in commented lines there are only Main and Contrib repositories without non-free, the main obstacle for Linux users to adopt non-free software is the lack of transparency on the code, you don’t really know what are you running in your device if the source code is restricted, but in some cases the user priorizes performance over this issue, for example, when installing a non-free driver.

Let’s focus on the 2 uncommented repositories which only allow us to look for  main packages:

deb http://mirror.isoc.org.il/pub/debian/ stretch main
deb-src http://mirror.isoc.org.il/pub/debian/ stretch main

Where:
deb: specifies it is a binary package:
deb-src: specifies the source code for the packages.
http://mirror.isoc.org.il/pub/debian/: specifies the repository’s root
stretch: specifies the OS version.
main: specifies the type of components available: main, contrib and non-free if available.

If we want our repositories to access contrib and/or non-free we only need to add it after “main”.
To edit our sources.list type:

nano /etc/apt/sources.list

After each line you want to enable contrib or non-free packages, add them at the end of each line as in the image, the previous two lines we focused on should be now:

deb http://mirror.isoc.org.il/pub/debian/ stretch main contrib non-free
deb-src http://mirror.isoc.org.il/pub/debian/ stretch main contrib non-free

Then after editing our sources.list  press CTRL+X to save and close and run an “apt update” to update our new enabled repositories:

As you see new sources were added and the output asks us to run “apt list –upgradable” to see what updates can we apply, run:

apt list –upgradable

As you see now we can install non-free firmwares which were unable before by running apt upgrade.

apt upgrade

How to add repositories in Debian

In some cases we would need to install software which isn’t included in Debian official repositories. For example, if we want to install VirtualBox from repositories we need to add them to our sources.list first.

First of all, try to install virtualbox using the default repositories by running:

apt install virtualbox

The package wasn’t found, now let’s add virtualbox repositories to our sources.list file by typing:

nano /etc/apt/sources.list

As you see at the end of the file I added the line

deb http://download.virtualbox.org/virtualbox/debian stretch contrib

Press ctrl+x to save and close and in order to update your repositories run:

apt update

Now let’s retry to install virtualbox from repositories by running:

apt install virtualbox

Now virtualbox is available but the installation requires us to specify the version we want to install. To install the last available version Type:

apt install virtualbox-6.0

As you see now we can install virtualbox from our repositories.

A different way to add a repository belonging to the software we want to install is possible, avoiding to edit the file /etc/apt/sources.list.

We can create a similar repository file within the /etc/apt/sources.list.d directory in the following way:

echo ‘deb http://download.virtualbox.org/virtualbox/debian ‘$(lsb_release -cs)
contrib non-free’
> /etc/apt/sources.list.d/virtualbox.list

Then run:

ls /etc/apt/sources.list.d

Where:
echo= will display the following string between ‘ ‘

‘deb http://download.virtualbox.org/virtualbox/debian ‘= contains the virtualbox repository address.

$(lsb_release -cs)= will print information on our Linux distribution, if we are unsure on our distro, we can call the command lsb_release -cs to define our version.

‘ contrib non-free’= we include non-free and contrib packages.

>= writes the output of the command to a file, in this case virtualbox.list.

/etc/apt/sources.list.d/virtualbox.list= the file in which the output (repository) will be written in.

To check the repository’s content run:

less /etc/apt/sources.list.d/virtualbox.list

Press Q to quit.

As you see the line is similar to the one we added to the sources.list file.

For this repository to be added, run:

apt update

Only after running “apt update” changes we do in our repositories will take place, otherwise the new source won’t be incorporated to our repositories. The same command should be executed always before a system upgrade (apt upgrade) to assure fresh versions and all repositories availability.

Despite the fact that we can always download our .deb installable package to install manually, managing repositories and installing software through them may make the installation process easier when our software has dependencies which is one of the apt command major advantages when installing or removing programs.

I hope you found this article useful to learn how to add repositories in your system. Before any inquiry about this process please don’t hesitate to contact us through our support channel at https://support.linuxhint.com.

Related articles:

Uninstall Ubuntu and Debian packages with apt-get and dpkg
List all installed packages on Debian

Related Posts
Leave a Reply

Your email address will not be published.Required fields are marked *