add-apt-repository

package managementlinux
The add-apt-repository command is one of the most frequently used commands in Linux/Unix-like operating systems. add-apt-repository The add-apt-repository command adds a new repository to the list of available APT package sources. It can add both standard repositories and Personal Package Archives (PPAs) to the system.

Quick Reference

Command Name:

add-apt-repository

Category:

package management

Platform:

linux

Basic Usage:

add-apt-repository [options] [arguments]

Common Use Cases

    Syntax

    add-apt-repository [options] repository

    Options

    Option Description
    -h, --help Show help message and exit
    -m, --massive-debug Print a lot of debug information
    -r, --remove Remove the specified repository
    -y, --yes Assume yes to all queries
    -s, --source Allow downloading of source packages from the repository
    -n, --no-update Do not update the package cache after adding the repository
    -u, --update Update the package cache after adding the repository (default)
    -k, --keyserver Specify a keyserver to receive keys from
    --key-id Specify a key ID to import from a keyserver
    -f, --filename Specify a filename to write sources list to (without .list)
    --disabled-repository Add the repository as disabled

    Examples

    How to Use These Examples

    The examples below show common ways to use the add-apt-repository command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    #

    Basic Examples:

    # Add a PPA repository
    add-apt-repository ppa:user/ppa-name
    # Add a standard repository add-apt-repository 'deb http://archive.ubuntu.com/ubuntu focal main'
    # Remove a repository add-apt-repository --remove ppa:user/ppa-name
    # Add a repository without updating package lists add-apt-repository --no-update ppa:user/ppa-name

    Advanced Examples:

    # Add a repository with source packages
    add-apt-repository --source 'deb-src http://archive.ubuntu.com/ubuntu focal main'
    # Add a repository and specify the keyserver add-apt-repository --keyserver keyserver.ubuntu.com ppa:user/ppa-name
    # Add a repository using a specific GPG key add-apt-repository --key-id ABCD1234 'deb http://example.com/repo stable main' # Add a repository and specify the sources list filename add-apt-repository --filename custom-repo 'deb http://packages.example.com/ubuntu focal main' # Add a repository without updating and without enabling it add-apt-repository --no-update --disabled-repository ppa:user/ppa-name

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    Understanding Repository Formats:

    The add-apt-repository command supports several repository formats:

    • PPA Format: ppa:user/ppa-name - For Ubuntu Personal Package Archives
    • Standard Format: deb http://site.example.com/debian distribution component1 component2 component3 - For standard Debian/Ubuntu repositories
    • Source Format: deb-src http://site.example.com/debian distribution component1 component2 component3 - For source package repositories

    GPG Key Management:

    When adding a repository, add-apt-repository automatically handles the GPG keys required to verify packages:

    • For PPAs, it fetches the key from the Ubuntu keyserver
    • For other repositories, you may need to specify a keyserver or key ID
    • The keys are stored in /etc/apt/trusted.gpg.d/ or older systems in /etc/apt/trusted.gpg

    Repository Storage:

    Added repositories are stored as files in specific locations:

    • PPAs: /etc/apt/sources.list.d/user-ppa-name-distribution.list
    • Standard repositories: /etc/apt/sources.list or /etc/apt/sources.list.d/filename.list if --filename is specified

    Package Updates:

    By default, add-apt-repository runs apt-get update after adding a repository to refresh the package index. This can be disabled with --no-update.

    Important Notes:

    • The add-apt-repository command requires root privileges (sudo)
    • On minimal installations, you may need to install software-properties-common to get this command
    • For Debian-based systems that aren't Ubuntu, you might need python3-software-properties
    • Repository additions persist across system reboots
    • Using unofficial repositories can potentially introduce unstable or insecure packages
    • Always verify the trustworthiness of a repository before adding it

    Removing Repositories:

    Use the --remove option to remove previously added repositories. This will:

    • Remove the repository from your sources
    • Remove the GPG key (in some cases)
    • Update the package cache (unless --no-update is specified)

    Related Commands

    These commands are frequently used alongside add-apt-repository or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the add-apt-repository command works in different scenarios.

    $ add-apt-repository
    View All Commands