VMHeaven

Troubleshooting

add-apt-repository: command not found — fix it on Ubuntu and Debian

The command lives in software-properties-common, which minimal images leave out and Debian 13 dropped. Install it, or add repositories by hand.

Updated 19 Sept 2026~5 min read

add-apt-repository: command not found — or sudo: add-apt-repository: command not found — means the helper is not installed. It is not part of apt. It is a small Python tool from the software-properties-common package, and minimal Ubuntu and Debian images, Docker bases and many WSL images leave that package out.

On Ubuntu, one package fixes it. On Debian the answer depends on the release: Debian 13 no longer ships the package at all, and on Debian you should not be adding Ubuntu PPAs in the first place. Both cases are covered below, along with the manual method, which works everywhere.

Ubuntu: install software-properties-common

Ubuntu
sudo apt update
sudo apt install -y software-properties-common

The command is available immediately — no reboot, no new shell. A typical PPA addition then looks like this. On current Ubuntu releases, add-apt-repository refreshes the package index by itself.

add a PPA
sudo add-apt-repository -y ppa:ondrej/php
sudo apt install -y <package-from-the-ppa>

Logged in as root in a container? Drop the sudo. If sudo itself is missing, see sudo: command not found.

Debian: it depends on the release

  • Debian 12 and oldersudo apt install software-properties-common works and gives you the command.
  • Debian 13 (trixie) — the package is gone. apt answers E: Unable to locate package software-properties-common, no matter how often you run apt update. Use the manual method below.

Add a repository without add-apt-repository

All the helper really does is download a signing key and write a sources file. Doing that by hand works on every Debian and Ubuntu release. It is also the better choice in Dockerfiles, because software-properties-common pulls in a full Python stack.

1 · signing key
sudo install -d -m 0755 /etc/apt/keyrings
curl -fsSL https://repo.example.com/key.gpg \
  | sudo gpg --dearmor -o /etc/apt/keyrings/example.gpg
2 · sources file (deb822 format)
sudo tee /etc/apt/sources.list.d/example.sources >/dev/null <<'EOF'
Types: deb
URIs: https://repo.example.com/apt
Suites: stable
Components: main
Signed-By: /etc/apt/keyrings/example.gpg
EOF

sudo apt update

Take the URL, suite and component names from the vendor’s install instructions. The older one-line format works too:

one-line equivalent
echo "deb [signed-by=/etc/apt/keyrings/example.gpg] https://repo.example.com/apt stable main" \
  | sudo tee /etc/apt/sources.list.d/example.list

Do not use apt-key add, even if old instructions tell you to. It trusts the key for every repository on the system, it has been deprecated for years, and newer releases have dropped it entirely. signed-by limits the key to one repository.

A PPA by hand (Ubuntu only)

This is useful in an Ubuntu container where you do not want software-properties-common. Copy the signing key fingerprint from the PPA’s Launchpad page, then:

Ubuntu · manual PPA
FPR=<fingerprint-from-launchpad>
curl -fsSL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x$FPR" \
  | sudo gpg --dearmor -o /etc/apt/keyrings/ondrej-php.gpg

sudo tee /etc/apt/sources.list.d/ondrej-php.sources >/dev/null <<EOF
Types: deb
URIs: https://ppa.launchpadcontent.net/ondrej/php/ubuntu
Suites: $(. /etc/os-release && echo "$VERSION_CODENAME")
Components: main
Signed-By: /etc/apt/keyrings/ondrej-php.gpg
EOF

sudo apt update

Installed, but it crashes with apt_pkg

If the command exists but fails with ModuleNotFoundError: No module named ‘apt_pkg’, the system Python was swapped out. add-apt-repository runs on /usr/bin/python3 and needs the distribution’s own version, which is the only one that has the python3-apt bindings. This usually happens after someone pointed python3 at a newer interpreter with update-alternatives.

check and repair
ls -l /usr/bin/python3          # should point at the distro's python3.x
sudo apt install --reinstall -y python3-apt

Call additional Python versions by their full name (python3.13, for example) instead of replacing the system python3. Parts of Ubuntu depend on it.

The RHEL, Rocky, Alma and Fedora equivalent

There is no add-apt-repository on dnf-based systems. The equivalents:

Rocky · Alma · RHEL · Fedora
# add a .repo file from a URL (dnf 4: EL 8/9)
sudo dnf install -y dnf-plugins-core
sudo dnf config-manager --add-repo https://repo.example.com/example.repo

# the same with dnf 5 (Fedora 41+)
sudo dnf config-manager addrepo --from-repofile=https://repo.example.com/example.repo

# EPEL, the big extra-packages repository (Rocky, Alma)
sudo dnf install -y epel-release

# Copr is the closest thing to a PPA
sudo dnf copr enable <owner>/<project>

Verify

verify
command -v add-apt-repository     # /usr/bin/add-apt-repository
apt policy <package>               # shows which repository a package comes from

If apt then stops with a lock error because a background update is running, see Could not get lock /var/lib/dpkg/lock.

Frequently asked

Which package provides add-apt-repository?

software-properties-common. On Ubuntu, 'sudo apt update && sudo apt install -y software-properties-common' makes the command available immediately.

Why can't I install software-properties-common on Debian 13?

The package is no longer part of Debian 13 (trixie). Add repositories manually with a keyring in /etc/apt/keyrings and a .sources file, or use extrepo for curated third-party repositories.

Can I add an Ubuntu PPA on Debian?

You should not. PPAs are built against Ubuntu releases and mixing their libraries into Debian tends to break later upgrades. Use the vendor's Debian repository or Debian backports instead.

More in Troubleshooting

See all