APT (Advanced Package Tool), is a package managing toolkit primarily responsible for repository configuration in Ubuntu and other Debian-centric Linux distros. APT uses a list of repositories to fetch software packages and updates. In this writing, I will discuss the basics & configuration of apt repositories in-depth along with some useful practical examples using the command line.
What is the APT Repository List?
APT repository list is a configuration file that contains a list of repositories from which APT fetches software packages. These repositories provide a wide range of software applications, updates, and security patches for your Linux system. Managing this list allows you to control which software is available for installation or update.
The APT Repository Configuration in Linux
Apt operates on top of repositories for software installation, updation, or even removal. It stores a list of repositories or software channels in the ‘/etc/apt/sources.list’ & ‘/etc/apt/sources.list.d/’ files. And, inside the repository list, you will find the URLs or addresses of the software repositories that APT should use to download & install packages.
So, knowing about the configuration file structure for software package management is a prime concern. Now about these two files:
- /etc/apt/sources.list: The primary file enlisting official repos. You can enable or disable any additional repositories by simply using the terminal that edits the file automatically.
- /etc/apt/sources.list.d/: A directory storing the configuration files with the .list extension. The sources.list file is also located here. You can add any necessary repository to use the required software by utilizing a .list file.
NOTE: Repository files in the ‘/etc/apt/sources.list.d’ directory must have file names ending with ‘.list’.
Components of APT Repository Entry
Each repository entry in the list specifies the location of the repository, the release code name (i.e., focal, bionic. etc.), and the sections of packages (main, restricted, universe, multiverse) available in that repository. The general syntax for entries in ‘/etc/apt/sources.list’ contains:
- deb → These repositories contain binaries or precompiled packages. They are required for most users.
- deb-src → They contain the source code of the packages. These are useful for developers.
- URL → This is the web address where the repository is hosted. For example, ‘http://archive.ubuntu.com/ubuntu/’ is the URL for the official Ubuntu repository.
- Release Code Name → Represents the code name of the specific Ubuntu release version, such as ‘jammy’ for Ubuntu 22.04.2 LTS.
- Sections → Ubuntu repositories are divided into four main sections:
- main: Contains officially supported open-source software & maintained by the Ubuntu community.
- restricted: Proprietary software that is supported by Ubuntu but not open-source.
- universe: Community-maintained open-source software.
- multiverse: Contains proprietary or restricted software not supported by Ubuntu.
Each section contains different software packages and users can choose which repositories to include in their system’s repository list based on their software requirements & preferences.
Managing APT Repositories in Ubuntu
Setting up software repositories using the CLI is a common practice for Linux users. You can manage your repositories by configuring apt repositories. More elaborately by adding, removing, and updating software sources, your system uses to install and update packages. Here’s how you can manage your repositories using a set of simple commands:
1. Listing the APT Repositories
To display the list of Ubuntu Repositories configured on your system, you can check the contents of the ‘/etc/apt/sources.list’ file and the files within the ‘/etc/apt/sources.list.d’ directory. You can also use the ‘apt-add-repository’ command with its option ‘–list’ to view all the repos lists. For that, use the command syntax:
sudo add-apt-repository --list
- sudo: Grants superuser privileges
- add-apt-repository: Command that adds/removes apt repositories.
- –list: Command option to list the current repositories.
2. Add a New APT Repository
Adding a new apt repository is a way to install software packages that are not available in the default repositories. To add a new repository, you can directly edit the ‘sources.list’ file or use the ‘add-apt-repository’ command.
Now, I will configure an apt repository for installing Chrome Browser. You can do the same by running the following command:
sudo add-apt-repository ‘deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ jammy main’
- deb: Repository type in Debian-based distro such as Ubuntu.
- [arch=amd64]: Architecture.
- https://dl.google.com/linux/chrome/deb/: Repository URL.
- jammy: Release codename for Ubuntu 22.04.
- main: Indicates software packages are within the main repository.
3. Remove an Existing APT Repository
Sometimes when you want to remove repositories that you no longer need, you can utilize the apt-add-repository command with the –remove option for a smooth deletion of those repositories.
Here, I will remove the previously added Chrome Browser. You can do the same by running the following command:
sudo add-apt-repository --remove ‘deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ jammy main’
- –remove: Option of the add-apt-repository command to delete the repository.
- https://dl.google.com/linux/chrome/deb/: Repository URL.
NOTE: You can disable any repositories, by just commenting out (by adding a ‘#’ at the beginning of the line) the corresponding repository lines from the ‘/etc/apt/sources.list’ configuration file.
4. Update Repository Lists
After modifying your repo list, you always need to update the package list to reflect the changes. This can be done by the following command:
sudo apt update
NOTE: Running the ‘sudo apt update’ command is an essential step after any repo modification to refresh the package information so that your system is aware of the latest changes.
APT Repository Mirror and Repository Proxy
Enhancing the software experience by improving download speeds and quick access to essential packages is crucial in the field of software package management. Two significant ways are known as Repository Mirrors and Repository Proxies. Check out the following section for more details on them:
APT Repository Mirror
The apt package manager usually installs and updates software by connecting to the official repositories. However, the central server may face a heavy load of traffic from time to time. This frustrates the faster download of the software. A repository mirror can be effective in situations as such.
The mirrors are duplicates of the official repositories. So, you can connect to the closest mirror based on the geographical location and ensure a quicker download of the software.
Benefits of Using Mirrors
- Faster package downloads, especially during peak times.
- Reduced strain on the primary repository servers.
- Increased reliability and availability of packages.
APT Repository Proxy
Also called APT Proxy, the apt repository proxy acts as an intermediary between your system and the remote repositories. It takes the system request and handovers to the external repository (either main or mirror) for further processing by functioning as the bridge between the repository server and the system user.
Benefits of Using Proxies
- Reduced bandwidth usage, particularly in environments with multiple Linux systems.
- Faster package installations and updates due to local caching.
- Enhanced control over which packages are cached and for how long.
Conclusion
Managing APT repository lists is a fundamental skill for any Linux user. By following the simple steps discussed in this writing, you can add, remove, and update repositories as needed to keep your system up to date and access to a wide range of software packages.
People Also Ask
Related Articles
- Ubuntu Repository List [A Total Guide]
- Debian Repository List [A Total Insight]
- A Complete Guide on Yum Repository List in Linux
- CentOS Repository List in Linux [A Complete Guide]
- Best Ubuntu Repositories [Choose Wisely]
<< Go Back to Linux Repository List | Package Management in Linux | Learn Linux Basics
FUNDAMENTALS A Complete Guide for Beginners