Resolve apt update errors when repositories lose Release files due to expired GPG keys, discontinued repos, or corrupted package manager state. Includes diagnostics, recovery methods, and prevention strategies.
Prerequisites
- Root or sudo access
- Basic command line knowledge
- Understanding of Linux package management
What this solves
The "E: Repository no longer has a Release file" error appears when apt update cannot verify a repository's authenticity or structure. This happens when repositories change their signing keys, discontinue services, or when your package manager cache becomes corrupted. This tutorial shows you how to diagnose the root cause, fix broken configurations, and prevent future repository issues.
Understanding repository structure and Release files
APT repositories use Release files to provide metadata about available packages and cryptographic signatures for verification. Each repository has a Release file containing package indexes, checksums, and expiration dates. When this file is missing, expired, or has invalid signatures, apt refuses to update to prevent potential security issues.
Repository URLs follow a specific structure: deb [options] URL distribution component. The Release file lives at URL/dists/distribution/Release and must be signed by a trusted GPG key in your /etc/apt/trusted.gpg.d/ directory.
Diagnosing the root cause
Check detailed apt update output
Run apt update with verbose output to see exactly which repositories are failing and why.
sudo apt update -vExamine repository sources
List all configured repositories to identify problematic sources.
grep -r "^deb" /etc/apt/sources.list /etc/apt/sources.list.d/Test repository accessibility
Manually check if the Release file exists for failing repositories.
curl -I http://example-repo.com/dists/focal/Release
curl -I https://example-repo.com/dists/focal/ReleaseCheck GPG key validity
Verify that repository signing keys are present and not expired.
apt-key list
gpg --list-keys --with-colons /etc/apt/trusted.gpg.d/*.gpgFixing corrupted or outdated repository configurations
Remove problematic repository entries
Comment out or remove failing repository entries from your sources.
sudo nano /etc/apt/sources.listAdd # at the beginning of problematic lines:
# deb http://old-repo.example.com/ubuntu focal main
deb http://archive.ubuntu.com/ubuntu focal main restrictedRemove repository-specific source files
Delete individual source files for discontinued repositories.
sudo rm /etc/apt/sources.list.d/problematic-repo.list
ls /etc/apt/sources.list.d/Update repository URLs
Replace old repository URLs with current mirrors or official sources.
sudo sed -i 's|http://old-repo.example.com|http://archive.ubuntu.com|g' /etc/apt/sources.listAdd missing GPG keys
Import GPG keys for repositories that have updated their signing keys.
curl -fsSL https://example-repo.com/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/example-repo.gpg
sudo apt updateRecovering from broken package manager state
Clear apt cache and lists
Remove cached repository data that might be corrupted.
sudo rm -rf /var/lib/apt/lists/*
sudo apt clean
sudo apt autocleanReset apt preferences
Remove pinning preferences that might interfere with repository access.
sudo rm -f /etc/apt/preferences
sudo rm -f /etc/apt/preferences.d/*Regenerate repository cache
Force apt to rebuild its repository cache from scratch.
sudo apt update --fix-missing
sudo apt updateFix broken package dependencies
Repair any package dependency issues caused by repository problems.
sudo apt --fix-broken install
sudo dpkg --configure -aAdvanced recovery techniques
Bypass signature verification temporarily
Only for emergency recovery when you trust the repository source.
sudo apt -o Acquire::AllowInsecureRepositories=true -o Acquire::AllowDowngradeToInsecureRepositories=true updateReset to minimal repository configuration
Create a clean sources.list with only essential repositories.
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backupFor Ubuntu systems:
deb http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu jammy-security main restricted universe multiverseFor Debian systems:
deb http://deb.debian.org/debian bookworm main contrib non-free
deb http://deb.debian.org/debian bookworm-updates main contrib non-free
deb http://security.debian.org/debian-security bookworm-security main contrib non-freeRebuild trusted keyring
Recreate the GPG keyring if it becomes corrupted.
sudo rm /etc/apt/trusted.gpg
sudo rm /etc/apt/trusted.gpg.d/*
sudo apt-key update
sudo apt updatePreventing future repository issues
Enable automatic key updates
Configure apt to automatically refresh repository keys before they expire.
APT::Key::gpgvcommand "/usr/bin/gpgv --keyring /etc/apt/trusted.gpg";
APT::Update::Pre-Invoke {"gpg --refresh-keys > /dev/null 2>&1 || true";};Set up repository monitoring
Create a script to check repository health regularly.
#!/bin/bash
set -e
echo "Checking repository accessibility..."
while IFS= read -r line; do
if [[ $line =~ ^deb[[:space:]]+([^[:space:]]+)[[:space:]]+([^[:space:]]+) ]]; then
url="${BASH_REMATCH[1]}"
dist="${BASH_REMATCH[2]}"
release_url="$url/dists/$dist/Release"
if curl -f -s --max-time 10 "$release_url" > /dev/null; then
echo "✓ $url ($dist) - OK"
else
echo "✗ $url ($dist) - FAILED"
fi
fi
done < <(grep -h "^deb " /etc/apt/sources.list /etc/apt/sources.list.d/* 2>/dev/null)
echo "Repository check complete."sudo chmod +x /usr/local/bin/check-repos.sh
/usr/local/bin/check-repos.shConfigure repository pinning
Set priorities for repositories to prevent conflicts between similar packages.
Package: *
Pin: origin archive.ubuntu.com
Pin-Priority: 500
Package: *
Pin: origin security.ubuntu.com
Pin-Priority: 500
Package: *
Pin: origin ppa.launchpad.net
Pin-Priority: 100Set up automated repository backup
Create backups of working repository configurations before making changes.
#!/bin/bash
BACKUP_DIR="/var/backups/apt-config"
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
sudo mkdir -p "$BACKUP_DIR"
sudo tar -czf "$BACKUP_DIR/apt-config-$TIMESTAMP.tar.gz" \
/etc/apt/sources.list \
/etc/apt/sources.list.d/ \
/etc/apt/trusted.gpg.d/ \
/etc/apt/preferences.d/ \
2>/dev/null
echo "APT configuration backed up to $BACKUP_DIR/apt-config-$TIMESTAMP.tar.gz"sudo chmod +x /usr/local/bin/backup-apt-config.sh
/usr/local/bin/backup-apt-config.shWorking with PPAs and third-party repositories
Safely add third-party repositories
Use the recommended method for adding PPAs and external repositories.
sudo apt install software-properties-common
sudo add-apt-repository ppa:example/ppa
sudo apt updateRemove problematic PPAs
Clean removal of PPAs that are causing issues.
sudo add-apt-repository --remove ppa:problematic/ppa
sudo apt updateDowngrade packages from removed repositories
Revert packages to versions available in official repositories.
sudo apt list --installed | grep -E '(ppa|local)'
sudo apt install package-name/jammy
apt-cache policy package-nameVerify your setup
Test that your repository configuration is working correctly.
sudo apt update
sudo apt list --upgradable
apt-cache policy
/usr/local/bin/check-repos.shCommon issues
| Symptom | Cause | Fix |
|---|---|---|
| "Release file expired" | Repository hasn't been updated | Remove or replace with current mirror |
| "GPG signature invalid" | Repository changed signing keys | Import new GPG key from repository |
| "Connection timeout" | Repository server offline | Switch to alternative mirror |
| "Hash mismatch" | Corrupted cache or partial download | Clear cache: sudo rm -rf /var/lib/apt/lists/* |
| PPA gives 404 error | PPA doesn't support your Ubuntu version | Remove PPA or use compatible version |
| "NO_PUBKEY" error | Missing GPG key | sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys KEYID |
| Conflicting repositories | Multiple sources for same packages | Set repository priorities with apt preferences |
Next steps
- Configure Linux package management with apt, dnf and yum for system updates
- Configure automatic security updates with unattended-upgrades and email notifications
- Set up APT-Cacher NG for local package mirroring
- Configure Debian package pinning and apt preferences
- Troubleshoot dpkg database corruption and recovery