How to Add a Package Repository to Debian

How to Add a Package Repository to Debian
On Linux a set of packages are installed by default. But the default packages are never enough. You may want to set up a file server, or a web server, or a database server or something else. For that you need to install additional packages. We use a package manager like apt to install and manage packages on Linux. The package manager downloads and installs packages from a package repository. A package repository is a HTTP or FTP server on the web where a set of packages are kept on the internet along with the package metadata that a package manager like apt downloads and uses first to find out what packages are available on the package repository. You can also have your own local package repository and add it on Debian.

In this article, I will show you how to add a package repository on Debian. I will use Debian 9 Stretch for the demonstration.

Adding a Package Repository Manually on Debian

The package repository information is stored on the /etc/apt/sources.list file. You may edit the /etc/apt/sources.list file directly to add a new package repository.

You can run the following command to edit /etc/apt/sources.list file:

$ sudo nano /etc/apt/sources.list

You should see the following window as shown in the screenshot below. As you can see, I have no package repository added here right now. You may have many package repositories added. But I want to show you the basics.

Now I am going to add the official Debian 9 package repository. So I am adding the following line to the file as marked in the screenshot below:

deb http://ftp.us.debian.org/debian stretch main contrib non-free

You may not understand what this line is yet. Let me explain.

The line starts with deb which means it’s a pre-compiled Debian binary repository. If the package repository contains source codes of different softwares, you should replace deb with deb-src.

Now the next section is the URL of the package repository. You can add HTTP, HTTPS, FTP repository URLs here.

The next section as marked in the screenshot below is the suite or codename. For Debian 9, it is stretch.

You may be able to find what it is for your Debian operating system with the following command:

$ lsb_release -cs

As you can see from the screenshot below, the codename or suite name is stretch.

The marked section of the screenshot below depends on the specific package repository that you’re adding. For the official Debian repository, you have main, contrib, and non-free.

Each of these words represents a section or set of software packages on the same package repository.

Once you’re done, press <Ctrl> + x and then press y and then press <Enter> to save the file.

Once you’re done adding a repository, run the following command to update the apt package manager cache:

$ sudo apt-get update

As you can see, the package repository cache is being updated.

There is also a cleaner way to add new package repositories on Debian.

On Debian operating systems, a special directory /etc/apt/sources.list.d/ is available by default. It is used to make adding new package repositories easier. All you have to do is create a new file with the extension .list in the /etc/apt/sources.list.d/ directory.

Instead of adding the new repository to the /etc/apt/sources.list file, you can create a new file let’s say debian_us_official.list in /etc/apt/sources.list.d/ directory with the following command:

$ sudo nano /etc/apt/sources.list.d/debian_us_official.list

A new empty file should be opened.

Now add the following line to it.

deb http://ftp.us.debian.org/debian stretch main contrib non-free

Now save the file and run the following command. You’re good to go.

$ sudo apt-get update

Adding a Package Repository Using apt on Debian

Now that you understand how a repository line is formatted. You can now use the apt package manager to add new package repositories.

To add the same repository as before, run the following command:

$ sudo apt-add-repository ‘deb http://ftp.us.debian.org/debian stretch main contrib non-free’

You can add a PPA as well with the following command:

$ sudo apt-add-repository YOUR_PPA

NOTE: Here YOUR_PPA should be something like ppa:teejee2008/ppa.

You can also remove a PPA or a package repository with the following command:

$ sudo apt-add-repository -r YOUR_REPOSITORY

NOTE: Here, YOUR_REPOSITORY may be a repository line or a PPA.

For example, in the screenshot below, I removed a repository using the repository line.

That’s how you add a repository on Debian. Thanks for reading this article.

Related Posts
Leave a Reply

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