The error “The repository is not updated and the previous index files will be used. GPG error: https://nginx.org/packages/mainline/debian bullseye InRelease: The following signatures were invalid” suggests that the GPG key for the Nginx repository is either missing, expired, or invalid. Here’s how to fix it in Debian 11 GNU Linux (Bullseye):
1. Remove Old Nginx GPG Keys
Old or conflicting keys can cause issues, so remove them first:
sudo rm -rf /etc/apt/keyrings/nginx* sudo rm -rf /usr/share/keyrings/nginx-archive-keyring.gpg
2. Add the Correct Nginx GPG Key
Run the following command to download and add the updated signing key:
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo gpg --dearmor -o /usr/share/keyrings/nginx-archive-keyring.gpg
Verify that the key was added:
gpg --show-keys /usr/share/keyrings/nginx-archive-keyring.gpg
3. Update the Repository Configuration
Ensure your /etc/apt/sources.list.d/nginx.list
contains the correct repository entry:
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] https://nginx.org/packages/mainline/debian bullseye nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
4. Update Package Lists
Now, refresh the package lists:
sudo apt update
If the update runs without errors, you can proceed with installation:
sudo apt install nginx
To fix error “The repository is not updated and the previous index files will be used. GPG error: https://packages.sury.org/apache2 bullseye InRelease: The following signatures were invalid” use commands:
curl -sSlo /usr/share/keyrings/sury-keyring.gpg https://packages.sury.org/php/apt.gpg curl -sSlo /usr/share/keyrings/apache2-keyring.gpg https://packages.sury.org/apache2/apt.gpg