Home UbuntuHow To Backup And Restore Installed Packages In Ubuntu Linux

How To Backup And Restore Installed Packages In Ubuntu Linux

By sk
1.2K views 7 mins read

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.

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:

DirectoryPurposeShould you back it up?
/usr/share/keyrings/Keyrings installed by packagesNo
/etc/apt/keyrings/Keys added by you for third-party reposYes

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 install

Or, if you installed any snap app with --classic flag, run:

tail -n +2 snaplist.txt | awk '{print $1}' | xargs -n1 sudo snap install --classic

5. 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)

Q. How do I back up the list of installed APT packages?

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.

Q: How do I restore packages from the backup file?

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.

Q: Do I need to back up /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.

Q: What is the simplest way to back up all my repository sources?

A: Copy these two items:

/etc/apt/sources.list
/etc/apt/sources.list.d/


That covers all APT repo entries on your system.

Q: How do I safely restore my repository sources?

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.

Q: Should I also back up GPG keys for repositories?

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/

Q: Will this work if I reinstall Ubuntu?

A: Yes, as long as the Ubuntu version is the same or very close. Large version jumps may cause missing or replaced packages.

Q: What should I do if some packages fail to install during restore?

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.

Q: Does this backup include custom configs from /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.

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.

You May Also Like

6 comments

id027102 November 15, 2025 - 2:43 pm

apt-key does not exist anymore
so post is not up yo date

Reply
sk November 15, 2025 - 4:42 pm

You’re right. I, somehow, missed that important step. Just updated the guide. Thanks for the comment. Much appreciated.

Reply
Paul Rehel November 16, 2025 - 11:30 am

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

Reply
sk November 17, 2025 - 12:19 pm

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.

Reply
Paul Rehel November 16, 2025 - 12:25 pm

Your missing coping sources.list.backup and sources.list.d.backup into ubuntu_packages.
And restoring from sources.list.d.backup.

Reply
sk November 17, 2025 - 1:10 pm

Good catch. I have fixed it commands (including the cheatsheet). Thanks again.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More