LinuxCommandLibrary

add-apt-repository

Add a new APT software repository

TLDR

Add a new apt repository

$ add-apt-repository [repository_spec]
copy

Remove an apt repository
$ add-apt-repository [[-r|--remove]] [repository_spec]
copy

Update the package cache after adding a repository
$ add-apt-repository --update [repository_spec]
copy

Allow source packages to be downloaded from the repository
$ add-apt-repository [[-s|--enable-source]] [repository_spec]
copy

SYNOPSIS

add-apt-repository [OPTIONS] REPOSITORY

PARAMETERS

REPOSITORY
    The repository to add or remove. This can be a PPA string (e.g., ppa:user/ppa-name) or a full APT line (e.g., "deb http://example.com/repo stable main").

-r, --remove
    Remove the specified repository from the system's software sources.

-y, --yes
    Assume 'yes' to all prompts, making the command non-interactive.

--no-update
    Do not run apt update after adding or removing the repository. By default, apt update is executed.

--update
    Explicitly run apt update after adding or removing the repository. This is the default behavior when --no-update is not specified.

--enable-max-https
    When adding a PPA, attempt to use maximum HTTPS security if available.

--ppa-dist-name DIST_NAME
    Specify the distribution name for the PPA (e.g., focal, jammy). This can be useful if the auto-detected distribution is incorrect.

DESCRIPTION

The add-apt-repository command simplifies the process of adding and removing APT (Advanced Package Tool) repositories on Debian-based Linux distributions, most notably Ubuntu. It is a wrapper script that automates several manual steps involved in managing software sources.

Historically, adding a new repository required manually editing /etc/apt/sources.list or creating a new file in /etc/apt/sources.list.d/, then separately fetching and adding the repository's GPG public key using apt-key (or modern methods like signed-by directives), and finally running apt update. add-apt-repository streamlines this entire workflow into a single command.

Its primary use case is integrating Personal Package Archives (PPAs) hosted on Launchpad, which provide newer software versions or packages not available in the official distribution repositories. It can also be used to add any standard deb or deb-src APT line. Upon successful addition, it automatically runs apt update (unless specified otherwise) to refresh the package lists, making the new packages available for installation.

CAVEATS

Adding arbitrary or untrusted repositories can pose significant security risks, as it grants the repository maintainer the ability to distribute any software, including malicious code, to your system. It can also lead to package conflicts or 'dependency hell' if the packages in the added repository clash with existing ones. It is advisable to only add repositories from trusted sources. add-apt-repository itself is typically provided by the software-properties-common package, which must be installed for the command to be available.

GPG KEY HANDLING

When a repository is added, add-apt-repository attempts to fetch the corresponding GPG public key from a keyserver (usually keyserver.ubuntu.com for PPAs) or directly from the repository's host. It then places this key into a secure location, typically a file under /etc/apt/trusted.gpg.d/, or adds a signed-by directive to the repository's configuration, ensuring that packages from the repository can be authenticated by apt.

BEHIND THE SCENES

For PPAs, add-apt-repository generally creates a new file in /etc/apt/sources.list.d/ (e.g., user-ubuntu-ppa-dist.list). This file contains the deb and potentially deb-src lines for the PPA. For generic APT lines, it might also create a file in this directory or modify /etc/apt/sources.list. This modular approach helps keep the software sources organized and simplifies management, as each repository gets its own dedicated configuration file.

HISTORY

add-apt-repository was introduced as part of the software-properties-common package, primarily for Ubuntu distributions. Its development aimed to simplify the management of Personal Package Archives (PPAs) hosted on Launchpad, which became a popular method for developers to distribute software outside of official repositories. Before this command, users had to manually perform multiple steps involving editing configuration files and using apt-key for GPG key management. add-apt-repository automated this process, making it more accessible to a wider range of users and integrating PPA management seamlessly into the system's package management workflow.

SEE ALSO

apt(8), apt-get(8), apt-key(8), sources.list(5)

Copied to clipboard