Reinstalling Ubuntu can feel like a fresh start, but soon after, I always face the same problem: reinstalling all my apps, PPAs, and settings one by one. It takes hours, and I often forget something important.
To solve this, I created a simple step-by-step workflow that allows me to backup all installed packages and configurations before a reinstall and restore them afterward in Ubuntu Linux.
In this guide, I'll explain how to backup and restore installed Ubuntu packages, including the configuration and dot files. This approach saves you a lot of time and reduces errors.
Table of Contents
Why Backup Installed Packages
In Ubuntu Linux, simply copying your home folder isn't enough. Without a proper backup, you will lose:
- Manually installed APT packages
- Extra PPAs or third-party repositories
- Snap and Flatpak apps
- Config files and dotfiles
By backing up your Ubuntu system properly, you can restore a fresh install to your previous working state without remembering every detail.
Without further ado, let us learn how to backup and restore installed packages, PPAs, Snap, Flatpak apps, and dotfiles in Ubuntu.
I tested the steps below on the latest Ubuntu 25.10 system, but I guess the same steps should work on any Ubuntu version and its derivatives such as Pop!_OS, Linux Mint, and Elementary OS etc.
Backup Installed Packages and Configs in Ubuntu
1. Create a Backup Directory
Create a directory to store all backups. Let us call it ubuntu_packages.
mkdir ubuntu_packages
Cd into it:
cd ubuntu_packages
2. Backup APT Packages
List all manually installed APT packages:
apt-mark showmanual > manual-pkgs.txt
This ensures only the apps you chose are saved, not system dependencies.
3. Backup Repositories and Keys
Save your repositories:
cp /etc/apt/sources.list sources.list.backup
cp -r /etc/apt/sources.list.d sources.list.d.backup
Backup repository GPG keys with command:
sudo tar -cvf repo-keyrings.tar /etc/apt/keyrings
For older Ubuntu versions that still use apt-key, you may export all keys:
sudo apt-key exportall > repo-keys.gpg
Note: Ubuntu uses two keyring locations:
| Directory | Purpose | Should you back it up? |
|---|---|---|
/usr/share/keyrings/ | Keyrings installed by packages | No |
/etc/apt/keyrings/ | Keys added by you for third-party repos | Yes |
We back up only the keys inside /etc/apt/keyrings.
4. Backup Snap and Flatpak Apps
Snap apps:
snap list > snaplist.txt
Flatpak apps:
flatpak list --app --columns=application > flatpaklist.txt
5. Backup Dotfiles and Configs
Copy essential configs:
mkdir -p backup-dotfiles cp -r ~/.bashrc ~/.profile ~/.gitconfig ~/.ssh ~/.config backup-dotfiles/
You can add other dotfiles like .vimrc or .zshrc if needed.
This is very important task. Copy the ubuntu_packages directory somewhere safe - an external USB drive or cloud storage. We need it to restore the packages after Ubuntu reinstallation.
Recommended Read:
Restore Ubuntu Packages from Backup
After reinstalling Ubuntu, you can restore the Ubuntu packages from the backup in this order.
1. Copy Backup Directory
Copy the ubuntu_packages folder back to your new Ubuntu installation.
Cd into the directory:
cd ubuntu_packages
2. Restore repositories and keys
sudo cp sources.list.backup /etc/apt/sources.list
sudo cp -r sources.list.d.backup /etc/apt/sources.list.d
sudo tar -xvf repo-keyrings.tar -C /
For older Ubuntu systems:
sudo apt-key add repo-keys.gpg
Update package lists:
sudo apt update
3. Reinstall APT packages
xargs -a manual-pkgs.txt sudo apt install -y
4. Restore Snap apps
tail -n +2 snaplist.txt | awk '{print $1}' | xargs -n1 sudo snap installOr, if you installed any snap app with --classic flag, run:
tail -n +2 snaplist.txt | awk '{print $1}' | xargs -n1 sudo snap install --classic5. Restore Flatpak apps
xargs -a flatpaklist.txt flatpak install -y
6. Copy back dotfiles
cp -r backup-dotfiles/. ~/
Best Practices
- Keep the backup folder on an external drive or cloud storage.
- Update the backup regularly if you install new apps.
- Secure sensitive files like SSH keys when syncing online.
Cheat Sheet: Quick Backup and Restore Commands
Backup
# Cd into the Backup directory
cd ubuntu_packages
# Backup manually installed APT packages
apt-mark showmanual > manual-pkgs.txt
# Backup repositories and keys
cp /etc/apt/sources.list sources.list.backup
cp -r /etc/apt/sources.list.d sources.list.d.backup
sudo tar -cvf repo-keyrings.tar /etc/apt/keyrings
# (Optional) For older Ubuntu versions that still rely on apt-key
sudo apt-key exportall > repo-keys.gpg
# Backup Snap apps
snap list > snaplist.txt
# Backup Flatpak apps
flatpak list --app --columns=application > flatpaklist.txt
# Backup dotfiles
mkdir -p backup-dotfiles
cp -r ~/.bashrc ~/.profile ~/.gitconfig ~/.ssh ~/.config backup-dotfiles/
Restore
# Cd into the Backup directory
cd ubuntu_packages
# Restore repositories and update
sudo cp sources.list.backup /etc/apt/sources.list
sudo cp -r sources.list.d.backup /etc/apt/sources.list.d
sudo tar -xvf repo-keyrings.tar -C /
# (Optional) For older Ubuntu systems only
sudo apt-key add repo-keys.gpg
# Update sources lists
sudo apt update
# Restore APT packages
xargs -a manual-pkgs.txt sudo apt install -y
# Restore Snap apps
tail -n +2 snaplist.txt | awk '{print $1}' | xargs -n1 sudo snap install --classic
# Restore Flatpak apps
xargs -a flatpaklist.txt flatpak install -y
# Restore dotfiles
cp -r backup-dotfiles/. ~/
Frequently Asked Questions (FAQ)
A: Create a plain text list with command:apt list --installed > installed-packages.txt
This file is light, easy to store, and enough for 80% of restore cases.
A: To restore backup, run:sudo xargs -a installed-packages.txt apt install
This installs every package listed in the file and skips missing ones.
/var/lib/apt/lists/?A: No. APT rebuilds those lists automatically during apt update. Backing them up wastes space and does not speed up recovery.
A: Copy these two items:/etc/apt/sources.list
/etc/apt/sources.list.d/
That covers all APT repo entries on your system.
A: Copy them back into place:sudo cp sources.list /etc/apt/
sudo cp -r sources.list.d/ /etc/apt/
sudo apt update
APT will refresh the package lists.
A: Yes. Most major errors during restore happen because GPG keys are missing.
Backup:sudo cp -r /etc/apt/keyrings/ keyrings-backup/
Restore:sudo cp -r keyrings-backup/* /etc/apt/keyrings/
A: Yes, as long as the Ubuntu version is the same or very close. Large version jumps may cause missing or replaced packages.
A: This usually happens because:
- Repo source is missing
- GPG key is missing
- Package no longer exists in that Ubuntu version
You can fix this by running:sudo apt update --fix-missing
Then run the restore command again.
/etc/?A: No. This method covers only packages and repo sources. If you want to back up system configuration, archive /etc/:sudo tar czvf etc-backup.tar.gz /etc/
Different Ways to Backup and Restore Ubuntu
Is this the only way to backup and restore apps in Ubuntu? Of course, not. There are many ways to backup and restore Linux systems. We have already published many guides on this topic. Check out the following links to learn more.
- How To Use Timeshift To Backup And Restore Linux System
- How To Restore Ubuntu Desktop And Server To Previous State Using Systemback
- Backup Installed Packages And Restore Them On Freshly Installed Ubuntu Using Apt-clone
- Backup And Restore Linux Desktop System Settings With Dconf
- SaveDesktop: An Easy Way to Save Your Linux Desktop Environment Configuration Settings
- How To Restore .bashrc File To Default Settings In Ubuntu
- Reset Linux Desktop To Default Settings With A Single Command
Conclusion
Reinstalling Ubuntu doesn't have to mean starting from scratch. By following these simple steps, I restored my system in a few minutes. My packages, repos, Snap/Flatpak apps, and configs are all back exactly as they were.
Do you have any better workflow for this same task? Please share it via the comment section below.

6 comments
apt-key does not exist anymore
so post is not up yo date
You’re right. I, somehow, missed that important step. Just updated the guide. Thanks for the comment. Much appreciated.
In manual-pkgs.txt includes linux-headers-##.., linux-image-unsigned-##.., linux-modules-##.., shouldn’t these be removed from the file?
sudo apt-key exportall > repo-keys.gpg
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)). <-still
I have added a note about the “apt-key” in the updated article. Also I have added how to backup the repo keys in recent Ubuntu versions. Please check again.
Your missing coping sources.list.backup and sources.list.d.backup into ubuntu_packages.
And restoring from sources.list.d.backup.
Good catch. I have fixed it commands (including the cheatsheet). Thanks again.