Jul 18, 2023 4 min read

“add-apt-repository” Command on Ubuntu 22.04

Learb about add-apt-repository Command in Ubuntu 22.04 with our tutorial. It is a tool on Linux for managing software repositories.

“add-apt-repository” Command on Ubuntu 22.04
Table of Contents

Introduction

The add-apt-repository command is a useful tool on Linux for managing software repositories. It allows users to easily add new software sources to their system, enabling them to install and update software packages with ease.

This command simplifies the process of adding third-party repositories, expanding the range of available software options. By using "add-apt-repository," Linux users can effortlessly enhance their systems and access a wider variety of software.

In this tutorial, you will learn how to install “add-apt-repository” command on Ubuntu 22.04.

Advantages of "add-apt-repository" Command

  1. Easy repository management: Simplifies the process of adding and managing software repositories on Linux.
  2. Expanded software options: Access a wider range of software packages by adding third-party repositories.
  3. Convenient installation and updates: Streamlines the installation and update process for software packages.
  4. Improved system customization: Enhance your Linux system by easily adding new software sources.
  5. Time-saving solution: Saves time by eliminating the need for manual configuration and simplifying repository management.

What is add-apt-repository command in Ubuntu 22.04

The "add-apt-repository" command in Ubuntu's /etc/apt/sources.list or /etc/apt/sources.list.d can assist users in downloading a repository or a few packages from a third party. The system can also be cleared of particular packages or repositories using this method.

Syntax

Use the following syntax in the terminal to run the “add-apt-repository” command with the necessary “option":

add-apt-repository [option] repository

The “add-apt-repository” command supports a number of significant options, including:

OptionsDescription
–removeIt is utilized to remove a repository or package.
–helpIt is utilized to get help messages.
–enable-sourceIt enables downloading packages from the repository.
–yesIt is utilized to accept all queries.

Methods to install “add-apt-repository” command in Ubuntu 22.04

Use the CTRL+ALT+T key combination to start a terminal and install the software-properties-common package before running the add-apt-repository command:

sudo apt install software-properties-common

The add-apt-repository command should be available to use in an Ubuntu 22.04 system when the mentioned package has been installed.

Let's examine how to use the add-apt-repository command to add a repository in Ubuntu 22.04.

Add third party repository using add-apt-repository command

We'll show you how to download a repository from an external source using this method.

Step 1 - Adding GPG key

It is necessary to first add a GPG key if we wish to install a repository directly from a third source rather than a PPA or Ubuntu repository. Use the command below to add a key:

wget -qO- https://download.webmin.com/jcameron-key.asc | sudo tee -a /etc/apt/trusted.gpg.d/jcameron-key.asc

Step 2 - Adding Webmin repository

Now we will add the Webmin repository to the Ubuntu source list using the "add-apt-repository" command. Use the command listed below to accomplish this:

sudo add-apt-repository "deb [arch=amd64] http://download.webmin.com/download/repository sarge contrib"

Step 3 - Installing Webmin

Ubuntu now understands where to look for a repository and install a certain application. The command shown below can be used to install Webmin:

 sudo apt install webmin -y

In the procedure above, add-apt-repository is used to install external source repositories on Ubuntu 22.04.

Add PPA repository using add-apt-repository command

The add-apt-repository command will now be used to add a PPA repository to our Ubuntu 22.04 system. In this approach, a GPG key does not need to be manually added because the add-apt-repository command can import it automatically. Therefore, we will include the “ansible” PPA repository for the demonstration.

Step1 - Update and Upgrade Ubuntu 22.04 repository

Using the command listed below, we will first update and upgrade the Ubuntu repository:

sudo apt update && sudo apt upgrade

Step 2 - Add Ansible repository

The add-apt-repository command will be used to add the Ansible PPA repository in the next step:

sudo add-apt-repository ppa:ansible/ansible

The GPG key is automatically imported by the "add-apt-repository" command, as shown below:

We'll now proceed with the "add-apt-repository" command's removal of a repository.

Using add-apt-repository command to remove a repository from Ubuntu 22.04

From the official Ubuntu apt repository, we can remove a repository. Use the -remove option that the add-apt-repository command supports to accomplish this. For demonstration purposes, we'll use the command shown below to remove the PPA ansible repository:

sudo add-apt-repository --remove ppa:ansible/ansible

It all comes down to adding the repository from any other sources. The add-apt-repository command has been used to remove any repository, and we have covered all the necessary steps to add a repository from a third party.

FAQs to “add-apt-repository” Command in Ubuntu 22.04

Can I add third-party repositories using "add-apt-repository"?

Yes, "add-apt-repository" allows you to add third-party repositories, expanding the software options available on your system.

How do I add a repository using "add-apt-repository"?

Use the command in the following format: sudo add-apt-repository <repository-url>. Replace <repository-url> with the actual URL of the repository.

Can I update the repository information after adding it?

Yes, you can update the repository information by running the command: sudo apt-get update.

How do I list the repositories added with "add-apt-repository"?

Run the command: sudo apt-cache policy to display a list of repositories along with their priorities.

Can I enable/disable a repository using "add-apt-repository"?

No, the "add-apt-repository" command only adds or removes repositories. To enable or disable a repository, you can modify the repository file manually.

Are there any risks in adding third-party repositories?

Adding third-party repositories may carry some risks. Ensure that you trust the repository source before adding it, as it could potentially introduce security or compatibility issues.

Can I use "add-apt-repository" on other Ubuntu versions?

Yes, the "add-apt-repository" command is available on various Ubuntu versions, including Ubuntu 22.04. However, some older versions may require additional package installations.

Conclusion

In Ubuntu 22.04, the add-apt-repository command is primarily used to add third-party packages and repositories. Use the terminal to run the command $ sudo apt install software-properties-common to install it.

With the add-apt-repository command, you can add any repository, enable sources, obtain help, uninstall any package or repository, and many other things. This tutorial goes into great detail on how to use add-apt-repository on Ubuntu 22.04.

If you have any suggestions or queries, kindly leave them in the comments section.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.