add-apt-repository: command not found means the package that provides the command is not installed. On Ubuntu 24.04 that package is software-properties-common: install it with apt-get install -y software-properties-common and the command works.

In the test, dpkg -S on /usr/bin/add-apt-repository named software-properties-common as its owner, and add-apt-repository -y universe ran to the end once it was installed.

The error

$ bash -c 'add-apt-repository universe'
bash: line 1: add-apt-repository: command not found
exit code: 127

The capture ran the command through bash -c, which is where the line 1: in the message comes from.

Why it happens

add-apt-repository is not part of apt itself. It is shipped in a separate package, and the ubuntu:24.04 image did not have that package, so bash found no file of that name on the PATH and returned 127. In the same container apt-get worked as usual: the missing piece was the one command, not the package manager. dpkg -S with the full path is how to find out which installed package owns a file, which is how the package name below was confirmed.

The fix

$ apt-get install -y software-properties-common > /tmp/spc.log 2>&1; tail -3 /tmp/spc.log
...
exit code: 0
$ command -v add-apt-repository
/usr/bin/add-apt-repository
exit code: 0
$ dpkg -S /usr/bin/add-apt-repository
software-properties-common: /usr/bin/add-apt-repository
exit code: 0
$ add-apt-repository -y universe
Hit:1 http://archive.ubuntu.com/ubuntu noble InRelease
Hit:2 http://security.ubuntu.com/ubuntu noble-security InRelease
...
Fetched 7607 kB in 3s (2178 kB/s)
Reading package lists...
...
Adding component(s) 'universe' to all repositories.
exit code: 0

After the install, command -v found the command in /usr/bin and the command enabled the universe component and refreshed the package lists itself. Run it as root or with sudo, as the test did as root. The W: ... configured multiple times lines cut from this capture came from an extra list file left by an earlier test in the same container, not from the install.

If you do not want the extra package, the alternative is to write the repository line by hand into a file under /etc/apt/sources.list.d/, as the related post below does for Docker's feed.

How it was reproduced

The capture was made in an ubuntu:24.04 container (Ubuntu 24.04.5 LTS, apt 2.8.3) on Docker Engine 29.9.3, standing in for Ubuntu in WSL. As root, add-apt-repository universe was run through bash -c; then software-properties-common was installed, the owner of the script was checked with dpkg -S, and the same command was run again.

Frequently asked

Which package provides add-apt-repository on Ubuntu?
On Ubuntu 24.04, software-properties-common. In the test dpkg -S /usr/bin/add-apt-repository printed software-properties-common as the owner.
Why is add-apt-repository not found in an Ubuntu Docker container?
The ubuntu:24.04 image did not include software-properties-common, so bash found no such command and returned exit code 127.
Can I add a repository without add-apt-repository?
Yes. Write the deb line into a file under /etc/apt/sources.list.d/ and run apt-get update. In the tests on this site, a third-party feed with no key failed with NO_PUBKEY, and one whose key file was named with signed-by= updated cleanly.

More decoded errors in the Fixes category. For a repository that needs its own signing key, see NO_PUBKEY, the public key is not available.