Website Vidya
Linux & ServersStep-by-Step Guide

How to Add APT Repository in Ubuntu 24.04 and 22.04

Learn how to add apt repository in ubuntu 24.04 with add-apt-repository, Launchpad PPAs, modern signed-by keyrings, DEB822 sources, and repository removal.

RR
Rajesh RayLead Systems Educator
Published:
6 min read
PDF Cheat Sheet
How to Add APT Repository in Ubuntu 24.04 and 22.04
AI Executive SummaryWebsiteVidya AI

6 min read

Learn how to add apt repository in ubuntu 24.04 with add-apt-repository, Launchpad PPAs, modern signed-by keyrings, DEB822 sources, and repository removal.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Understanding APT Repositories, PPAs, and DEB822 Sources
  • Step 2: Installing software-properties-common
Grounded in full engineering runbookWebsiteVidya AI Engine

The Advanced Package Tool (APT) is the package management system powering Ubuntu and Debian distributions.

While Ubuntu's default software repositories contain tens of thousands of tested, stable packages, developers and system administrators frequently need access to newer software versions, proprietary drivers, or specialized tools not included in the standard distribution archives.

Adding custom repositories allows your system to discover, download, install, and automatically receive security updates for third-party software alongside official packages.

In this guide, we walk through how to add apt repository in ubuntu 24.04 using official Launchpad PPAs, modern cryptographically verified GPG keyrings, DEB822 configuration files, and clean repository removal practices.

Advertisement

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Before proceeding, ensure you have the following requirements satisfied:

  • A computer or server running Ubuntu 24.04 LTS or Ubuntu 22.04 LTS.
  • A non-root user account with sudo administrative privileges.
  • Basic familiarity with the Linux terminal command-line interface.

Step 1: Understanding APT Repositories, PPAs, and DEB822 Sources

An APT repository is a network server hosting compiled Debian packages (.deb) alongside index files and cryptographic signatures.

Advertisement

Ubuntu divides its official software archives into four main components: main (canonical-supported open-source software), restricted (proprietary drivers), universe (community-maintained open-source software), and multiverse (software restricted by copyright or legal issues).

Beyond official components, developers use Personal Package Archives (PPAs) hosted on Canonical's Launchpad to distribute pre-compiled packages.

In Ubuntu 24.04, Canonical transitioned the default package configuration from traditional one-line /etc/apt/sources.list files to structured DEB822 format in /etc/apt/sources.list.d/ubuntu.sources, improving readability and security metadata handling.

Step 2: Installing software-properties-common

The primary command-line tool for adding and managing PPAs on Ubuntu is add-apt-repository.

Advertisement

This utility is provided by the software-properties-common package, which is installed by default on desktop editions but may be omitted on minimal cloud server images.

Update your local package index and verify that the package is installed:

# Update repository cache:
sudo apt update

# Install software-properties-common:
sudo apt install -y software-properties-common

# Verify add-apt-repository availability:
add-apt-repository --help

Step 3: Adding a Personal Package Archive (PPA)

PPAs allow individual developers and teams to distribute software builds directly to Ubuntu users through Launchpad.

When you add a PPA using add-apt-repository, the utility automatically queries Launchpad, downloads the publisher's public GPG signing key, adds the repository URL to your APT configuration, and updates your package cache.

For example, to install the latest Git release directly from the official Git maintenance team's PPA, run:

# Add the Git team stable PPA:
sudo add-apt-repository -y ppa:git-core/ppa

# Notice on Ubuntu 20.04 and newer, APT cache updates automatically.
# Install or upgrade Git from the newly added repository:
sudo apt install -y git

# Verify installed Git version:
git --version
# Output confirms latest upstream release from PPA.

Step 4: Adding Third-Party Repositories with Modern signed-by Keyrings

Historically, third-party software vendors instructed users to run apt-key add to import repository signing keys.

However, apt-key has been completely deprecated because keys added globally via apt-key were trusted to sign packages from any repository on the system, creating a significant security risk.

The modern, secure standard requires storing public GPG keys in isolated files under /etc/apt/keyrings/ and explicitly scoping the key to its specific repository using the signed-by directive.

Here is the standard workflow demonstrated using the official NodeSource Node.js repository:

# 1. Install prerequisites:
sudo apt update && sudo apt install -y ca-certificates curl gnupg

# 2. Create dedicated keyrings directory with secure permissions:
sudo install -m 0755 -d /etc/apt/keyrings

# 3. Download and dearmor vendor public GPG key into keyrings:
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | \
  sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
sudo chmod a+r /etc/apt/keyrings/nodesource.gpg

# 4. Add the repository source file with explicit signed-by scoping:
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | \
  sudo tee /etc/apt/sources.list.d/nodesource.list > /dev/null

# 5. Refresh package list:
sudo apt update

Step 5: Understanding Ubuntu 24.04 DEB822 Format (.sources)

Starting with Ubuntu 24.04 LTS, Ubuntu transitioned its primary repository definitions to the multi-line DEB822 standard format.

Instead of a single long line beginning with deb http://..., DEB822 files use stanza blocks with explicit field names.

You can create custom third-party repositories using DEB822 format in /etc/apt/sources.list.d/example.sources:

Here is an example structure illustrating how a repository is represented in DEB822 format:

# /etc/apt/sources.list.d/example.sources
Types: deb
URIs: https://download.example.com/linux/ubuntu
Suites: noble
Components: stable
Architectures: amd64 arm64
Signed-By: /etc/apt/keyrings/example.gpg

Step 6: Removing and Disabling Repositories and Keys

If a repository becomes deprecated, abandoned, or unnecessary, remove it to prevent connection timeouts and security vulnerabilities during apt update.

To remove a PPA, pass the --remove flag to add-apt-repository:

To remove a third-party repository installed via keyrings, delete the configuration file from /etc/apt/sources.list.d/ and remove its corresponding GPG key from /etc/apt/keyrings/:

# Remove a Launchpad PPA:
sudo add-apt-repository --remove -y ppa:git-core/ppa

# Remove custom third-party repository and keyring:
sudo rm -f /etc/apt/sources.list.d/nodesource.list
sudo rm -f /etc/apt/keyrings/nodesource.gpg

# Refresh package cache:
sudo apt update

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

W: GPG error: ... The following signatures couldn't be verified because the public key is not available: NO_PUBKEY [KEY_ID]

Cause: The repository signing key is missing, expired, or improperly imported into APT.

Resolution: Download the missing public key using gpg --keyserver or vendor instructions into /etc/apt/keyrings/.

sudo gpg --keyserver keyserver.ubuntu.com --recv-keys [KEY_ID]

E: Conflicting distribution: ... 404 Not Found

Cause: The added repository does not offer pre-compiled packages for your Ubuntu release codename (e.g. noble or jammy).

Resolution: Check vendor documentation for supported Ubuntu versions or remove the repository source file.

cat /etc/os-release | grep VERSION_CODENAME

add-apt-repository: command not found

Cause: The software-properties-common package is not installed on your minimal system.

Resolution: Install the utility using sudo apt update && sudo apt install -y software-properties-common.

sudo apt install -y software-properties-common

Security Best Practices and Hardening

Never add untrusted personal repositories or execute random curl-to-bash installation scripts from unverified websites.

Avoid using deprecated apt-key add commands; always store third-party keys in /etc/apt/keyrings/ with the signed-by attribute.

Verify repository integrity by checking fingerprint signatures against the vendor's official published security advisory.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

4 FAQs
A standard repository is hosted and maintained by Canonical or a third-party software organization. A PPA (Personal Package Archive) is hosted directly on Canonical's Launchpad platform and maintained by independent developers or software teams.
apt-key added keys globally into a shared keyring (/etc/apt/trusted.gpg). This allowed any imported key to authenticate packages from any configured repository. The modern signed-by standard confines each key to its specific repository.
Individual repository definition files reside in /etc/apt/sources.list.d/ as .list or .sources files.
Yes. On Ubuntu 18.04 and all newer releases, add-apt-repository automatically triggers an internal apt update after adding or removing a repository.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout