The Fix
The error "add-apt-repository: command not found" means the package that provides the command is not installed. On Ubuntu:
sudo apt update
sudo apt install software-properties-common
Check that it works with add-apt-repository --help. The name apt-add-repository starts the same tool. For other missing commands, see command not found in Linux.
Before You Add a Repository
Packages run install scripts as root, and a repository can ship a newer version of any package, including ones you already have. Adding a repository means trusting its publisher with root on the server. Work in this order:
- Check whether the distribution already packages the software:
apt-cache policy package. - If not, use the vendor's own documented repository.
- Use a PPA only when you know and trust who maintains it.
A PPA (personal package archive) is a repository on Launchpad built by an individual or a team for specific Ubuntu releases.
Add a PPA
sudo add-apt-repository ppa:owner/name
sudo apt update
sudo apt install package
The tool imports the PPA's signing key and writes a repository file under /etc/apt/sources.list.d/. Current releases refresh the package lists on their own after adding; running sudo apt update again does no harm. To confirm which source a package will come from, run apt-cache policy package.
Remove a PPA
sudo add-apt-repository --remove ppa:owner/name
sudo apt update
Removing the source does not downgrade what it installed. The ppa-purge tool removes the PPA and returns its packages to the Ubuntu versions:
sudo apt install ppa-purge
sudo ppa-purge ppa:owner/name
Take a snapshot before you do this on a production server.
Debian and PPAs
PPAs are built against Ubuntu's libraries. On Debian they can pull in dependencies that do not match, which leaves packages that cannot be upgraded cleanly. Do not add PPAs to Debian. Use Debian's own packages or backports, or a vendor repository that names your Debian release, written by hand as shown below. The differences between the two systems are covered in Debian vs Ubuntu Server.
Add a Vendor Repository by Hand
Keep each key in /etc/apt/keyrings and tie it to its repository with signed-by. Do not use apt-key: it is deprecated and trusted a key for every repository at once.
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSLo /tmp/example.asc https://example.com/apt/key.asc
gpg --show-keys /tmp/example.asc
sudo gpg --dearmor -o /etc/apt/keyrings/example.gpg /tmp/example.asc
Compare the fingerprint that gpg --show-keys prints with the one in the vendor's documentation. Then create the repository file:
sudo nano /etc/apt/sources.list.d/example.sources
Types: deb
URIs: https://example.com/apt
Suites: stable
Components: main
Signed-By: /etc/apt/keyrings/example.gpg
The older one-line format does the same in a file ending in .list:
deb [signed-by=/etc/apt/keyrings/example.gpg] https://example.com/apt stable main
Finish with sudo apt update. Use the suite and component names the vendor gives; some use your release codename, which lsb_release -cs prints.
Errors After Adding a Repository
- Missing public key: the key file is missing, or the
signed-bypath does not match it. - No Release file: the repository does not publish packages for your release. Remove the entry.
- Conflicting values for Signed-By: the same repository is listed twice with different keys. Keep one file.
Regular update commands are explained in sudo apt update.