How to Add APT Repository in Ubuntu

By 

Updated on

6 min read

Adding an APT repository on Ubuntu using add-apt-repository

When installing packages using apt, the packages are downloaded from one or more software repositories. An APT repository is a network server or a local directory containing deb packages and metadata files that are readable by the APT tools.

There are thousands of applications available in the default Ubuntu repositories, but sometimes the package you need lives in a third-party repository. The same is true on Ubuntu 26.04, which keeps the DEB822 source format introduced in 24.04 and continues to manage repository keys through /etc/apt/keyrings/.

This guide explains how to add APT repositories on Ubuntu and Debian systems using the add-apt-repository command, the signed-by method, and manual source files.

Quick Reference

TaskCommand
Install add-apt-repositorysudo apt install software-properties-common
Add a repositorysudo add-apt-repository "deb [signed-by=...] URL suite component"
Remove a repositorysudo add-apt-repository --remove "deb ..."
Add a PPAsudo add-apt-repository ppa:user/ppa-name
Remove a PPAsudo add-apt-repository --remove ppa:user/ppa-name
Download a GPG keycurl -fsSL URL | sudo gpg --dearmor -o /etc/apt/keyrings/key.gpg
Update package indexsudo apt update
List repositoriesapt policy

Understanding APT Sources

On Ubuntu and all other Debian-based distributions, apt software repositories are defined in the /etc/apt/sources.list file or in separate files under the /etc/apt/sources.list.d/ directory.

One-Line Format

The traditional one-line format uses .list files and looks like this:

ini
deb [signed-by=/etc/apt/keyrings/example.gpg] https://example.com/ubuntu noble main
  • deb or deb-src - The archive type. deb means binary packages, deb-src means source packages.
  • signed-by - Path to the GPG key that authenticates the repository.
  • URL - The repository address.
  • Distribution - The release codename, such as resolute (26.04), noble (24.04), or jammy (22.04).
  • Components - The repository categories. The default Ubuntu repositories use main, restricted, universe, and multiverse. Third-party repositories typically have only one component.

DEB822 Format

Starting with Ubuntu 24.04 and continuing on Ubuntu 26.04, the default repository configuration uses the DEB822 format in .sources files. This format is more readable and structured:

/etc/apt/sources.list.d/example.sourcesini
Types: deb
URIs: https://example.com/ubuntu
Suites: noble
Components: main
Signed-By: /etc/apt/keyrings/example.gpg

Both formats work on modern Ubuntu versions. The DEB822 format is recommended for new configurations.

Repository Authentication

Repositories provide a public GPG key to authenticate downloaded packages. The modern approach stores keys in the /etc/apt/keyrings/ directory and references them with the signed-by option in the source entry.

Warning
The apt-key command is deprecated and last available in Ubuntu 24.04. Do not use apt-key add or apt-key adv to import repository keys. Use the signed-by method described in this guide instead.

To add or remove a repository you need to be logged in as either a user with sudo access or root.

Installing add-apt-repository

add-apt-repository is a utility that allows you to add an APT repository to /etc/apt/sources.list.d/. It can also be used to remove an existing repository.

If add-apt-repository is not available on your system, you will get the following error message:

output
sudo: add-apt-repository: command not found

The utility is included in the software-properties-common package. To install it, run:

Terminal
sudo apt update
sudo apt install software-properties-common

Adding Repositories with add-apt-repository

The basic syntax of the add-apt-repository command is as follows:

txt
add-apt-repository [options] repository

Where repository can be either a regular repository entry like deb https://example.com/ubuntu noble main or a PPA repository in the ppa:<user>/<ppa-name> format.

By default, add-apt-repository also updates the package index after adding the repository. The package index is a database that holds records of available packages from all enabled repositories.

Adding a Third-Party Repository

For example, to add the Docker repository on Ubuntu, first download and store the GPG key:

Terminal
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

Then add the repository:

Terminal
sudo add-apt-repository \
  "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

$(lsb_release -cs) prints the Ubuntu codename. On Ubuntu 24.04 it prints noble, and on Ubuntu 26.04 it prints resolute.

If you are on an ARM system (for example, a Raspberry Pi), replace arch=amd64 with arch=arm64 or the architecture you use.

For a full Docker setup on the latest release, see the Docker on Ubuntu 26.04 guide.

You can now install packages from the newly enabled repository:

Terminal
sudo apt install docker-ce

Removing a Repository

To remove a previously added repository, use the --remove option:

Terminal
sudo add-apt-repository --remove "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Adding PPA Repositories

Personal Package Archives (PPA) is a service that allows users to upload Ubuntu source packages that are built and published with Launchpad as an apt repository.

When adding a PPA repository, add-apt-repository creates a new file under the /etc/apt/sources.list.d/ directory and automatically downloads the repository public key.

For example, to add the Graphics Drivers PPA:

Terminal
sudo add-apt-repository ppa:graphics-drivers/ppa

When prompted, press Enter and the repository will be enabled:

output
Press [ENTER] to continue or Ctrl-c to cancel adding it.

Once the PPA is added, you can install packages from it:

Terminal
sudo apt install nvidia-driver-560

The apt command will install the package and all its dependencies.

To remove a PPA, use the --remove option:

Terminal
sudo add-apt-repository --remove ppa:graphics-drivers/ppa

Manually Adding Repositories

If you want more control over how your sources are organized, you can manually create repository files. This is the recommended approach for third-party repositories.

Using the One-Line Format

Create a new .list file under /etc/apt/sources.list.d/. For example, to add the Kubernetes repository:

First, download the GPG key:

Terminal
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.34/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes.gpg

Then create the repository file:

Terminal
echo "deb [signed-by=/etc/apt/keyrings/kubernetes.gpg] https://pkgs.k8s.io/core:/stable:/v1.34/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list

Using the DEB822 Format

On Ubuntu 24.04 and newer, including Ubuntu 26.04, you can use the DEB822 .sources format. For the same Kubernetes repository:

Terminal
sudo tee /etc/apt/sources.list.d/kubernetes.sources << 'EOF'
Types: deb
URIs: https://pkgs.k8s.io/core:/stable:/v1.34/deb/
Suites: /
Signed-By: /etc/apt/keyrings/kubernetes.gpg
EOF

After adding the repository, update the package index and install the packages:

Terminal
sudo apt update
sudo apt install kubelet kubeadm kubectl

Removing a Manually Added Repository

To remove a manually added repository, delete its .list or .sources file and update the package index:

Terminal
sudo rm /etc/apt/sources.list.d/kubernetes.list
sudo apt update

Listing Enabled Repositories

To see all enabled repositories on your system, you can check the source files:

Terminal
apt policy

This command displays all configured repositories and their priorities.

To list the repository files:

Terminal
ls /etc/apt/sources.list.d/

FAQ

Is apt-key still supported?
No. apt-key is deprecated and last available in Ubuntu 24.04. Use the signed-by option with keys stored in /etc/apt/keyrings/ instead.

What is the difference between .list and .sources files?
.list files use the traditional one-line format. .sources files use the newer DEB822 format, which is more structured and readable. Both work on modern Ubuntu versions, but DEB822 is the default format starting with Ubuntu 24.04.

Do I need to run apt update after adding a repository?
If you use add-apt-repository, it updates the package index automatically. If you add the repository manually, you need to run sudo apt update before installing packages from it.

Can I add Ubuntu PPAs on Debian?
Technically possible, but not recommended. PPA packages are built for Ubuntu and may have incompatible dependencies on Debian systems.

Where should I store GPG keys?
Store repository GPG keys in /etc/apt/keyrings/. This directory is the standard location recommended by Debian and Ubuntu.

Conclusion

You now have three reliable ways to add APT repositories on Ubuntu and Debian: add-apt-repository, PPA entries, and manual source files in either the one-line or DEB822 format. The same instructions apply to any Debian-based distribution, including Kubuntu, Linux Mint, and elementary OS.

If you are setting up a fresh system, see the guide on upgrading to Ubuntu 26.04 for the matching distribution release.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page