add-apt-repository
Quick Reference
Command Name:
add-apt-repository
Category:
package management
Platform:
linux
Basic Usage:
Common Use Cases
- 1
Software repository management
Add third-party repositories to access additional software packages
- 2
PPA integration
Add Personal Package Archives for Ubuntu-specific software
- 3
Development tools installation
Add repositories for development libraries and tools
- 4
Latest software access
Access cutting-edge software versions from external repositories
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 repositorysudo add-apt-repository ppa:ubuntu-toolchain-r/test# Add a repository with a specific distribution
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu focal main"# Add a repository with a specific component
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"# Add a repository and update package list
sudo add-apt-repository ppa:ondrej/php && sudo apt update
Advanced Examples:
# Add a repository with a specific keysudo add-apt-repository "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu focal stable"# Add a repository with a specific suite
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu focal-security main"# Add a repository with a specific architecture
sudo add-apt-repository "deb [arch=i386] http://archive.ubuntu.com/ubuntu focal main"# Add a repository with a specific source
sudo add-apt-repository "deb-src http://archive.ubuntu.com/ubuntu focal main"# Add a repository with a specific target
sudo add-apt-repository -y ppa:ondrej/php
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)
Common Use Cases
Software repository management
Add third-party repositories to access additional software packages
PPA integration
Add Personal Package Archives for Ubuntu-specific software
Development tools installation
Add repositories for development libraries and tools
Latest software access
Access cutting-edge software versions from external repositories
System customization
Expand available software options beyond default repositories
Related Commands
These commands are frequently used alongside add-apt-repository
or serve similar purposes:
Use Cases
Software repository management
Add third-party repositories to access additional software packages
PPA integration
Add Personal Package Archives for Ubuntu-specific software
Development tools installation
Add repositories for development libraries and tools
Latest software access
Access cutting-edge software versions from external repositories
System customization
Expand available software options beyond default repositories
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.