As a Linux administrator it is very important to know how you are managing your applications & Software’s. Every command and every installation of packages require critical attention before executing it.
So In this Ultimate guide we will learn everything you should know about ubuntu repositories , how to add apt-repository & PPA repositories and working with ubuntu repository and apt commands.
Table of Content
- What is ubuntu repository?
- How to add a ubuntu repository?
- Manually Adding apt-repository in ubuntu
- Adding PPA Repositories
- Working with Ubuntu repositories
- How apt or apt-get command work with Ubuntu Repository
- Conclusion
What is ubuntu repository?
APT repository is a network shared server or a local directory containing deb packages and metadata files that are readable by the APT tools. When installing packages using the Ubuntu Software Center or the command line utilities such as apt
or apt-get
the packages are downloaded from one or more apt software repositories.
On Ubuntu and all other Debian based distributions, the apt software repositories are defined in the /etc/apt/sources.list
file or in separate files under the /etc/apt/sources.list.d/
directory.
The names of the repository files inside the /etc/apt/sources.list.d/
directory must end with .list
.
How to add apt-repository in ubuntu ?
add-apt-repository
is basically a python script that helps in addition of repositories in ubuntu.
Lets take a example to add a mongodb repository in ubuntu machine
add-apt-repository
utility is included insoftware-properties-common
package.
sudo apt update
sudo apt install software-properties-common

- Import the repository public key by running
apt-key
command
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4

- Add the MongoDB repository using the command below.
sudo add-apt-repository 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse'

Manually Adding apt-repository in ubuntu
To add repositories manually in ubuntu edit the /etc/apt/sources.list
file and add the apt repository line to the file.
To add the repository open the sources.list
file with your favorite editor
sudo vi /etc/apt/sources.list
Add the repository line to the end of the file:
sudo add-apt-repository 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse'
- If required to add manually public key for which you can use
wget
orcurl
command
Adding PPA Repositories
Personal Package Archives (PPA) allows you to upload Ubuntu source packages that are built and published with Launchpad as an apt repository.
When you add a PPA repository the add-apt-repository
command creates a new file under the /etc/apt/sources.list.d/
directory.
Lets take a example of Addition of ansible PPA repository in ubuntu machine
PPA
utility is included insoftware-properties-common
package similar toadd-apt-repository
sudo apt update
sudo apt install software-properties-common
- Add PPA ansible Repository in the system.
sudo apt-add-repository --yes --update ppa:ansible/ansible
# PPA is Personal Package Archive

- Lets check the directory /etc/apt/sources.list.d/ has ansible PPA repository

Working with Ubuntu repositories
Repositories in ubuntu machine are basically file servers or network shares under which it has lot of packages , it could be .deb packages or files which are readable by apt
or apt-get
command.
/etc/apt/sources.list or
/etc/apt/sources.list.d

What does sources.list
and sources.list.d
contains ?
- Software in Ubuntu’s repository is divided into four categories or components – main, restricted, universe and multiverse.
- main: contains applications that are free software that are fully supported by ubuntu.
- multiverse: contains software’s that are not free that requires license.
- restricted: only to promote free software and ubuntu team cannot fix it & then provide it back to author if any issues are found.
- universe: They have all the possible software’s which are free and open sourced but ubuntu don’t provide regular patch guarantee.
deb http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ bionic main restricted
deb-src http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ bionic main restricted
deb http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ bionic-updates main restricted
deb-src http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ bionic-updates main restricted
deb http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ bionic universe
deb-src http://security.ubuntu.com/ubuntu bionic-security multiverse
deb
ordeb-src
are either .deb packages or source code- http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ is the
repository URL
- bionic , bionic-security , xenial are distributions code name.
- main, restricted, universe and multiverse are repository categories.

How apt or apt-get command work with Ubuntu Repository
APT stands for Advanced Packaging Tool which performs functions such as installation of new software packages, upgrade of existing software packages, updating of the package list index, and even upgrading the entire Ubuntu system by connecting with repositories stored under /etc/apt/sources.list
or /etc/apt/source.list.d
/
Let us see an example of how apt command works with ubuntu repositories.
- Install below three packages
apt install curl
apt install wget
apt install telnet

- You will notice that all the above packages are already up to date and latest
- Now run the
apt update
command to update the repositories. apt command contains three types of lines.- Hit: If there is no change in package version from the previous version
- Ign: It means package is being ignored.
- Get: It means it has a new version available. It will download the information about the version (not the package itself). You can see that there is download information (size in kb) with the ‘get’ line in the screenshot above.
apt update


- After completion of command it provides the details if upgrade is required by any package or not. In our case it shows 37 packages can be upgraded. Lets see the list of packages which can be upgraded by running the following command.
apt list --upgradable

You can either upgrade a single package or upgrade all packages together.
To upgrade a single package use : apt install <package-name>
To upgrade all packages use : apt upgrade
- Lets just update the curl package by running the
apt install
command and verify
apt install curl
- You will notice that updating curl command upgraded 2 packages which were related to curl and rest of 35 are still not upgraded.

- Now, lets upgrade rest of the 35 packages together by running
apt upgrade
command.
apt upgrade

- Lets run
apt update
command again to verify if ubuntu still requires any software to be upgrade. Command output should look like “All packages are up to date”
apt update

Conclusion
In this tutorial we learnt everything about ubuntu repositories and how to add various repositories and how to work with them . Finally we saw how apt command works with ubuntu repositories.
This Ultimate Guide will give you a very strong understanding of package management which is most important thing for a Linux administrator. Hope you liked this tutorial and was helpful. Please share.