1. Home
  2. Linux
  3. Quickly re install all installed apps on fedora

How to quickly re-install all installed apps on Fedora

Re-installing programs on Fedora Linux can take a long time. Mainly because, to do it, you need to look at DNF for your installed applications, figure out the names, and manually write out every app you’d like to set up.

Rather than sitting down and manually installing everything, you can automate it by exporting all packages through the  Fedora app installer to an easy to use installation script.

Export all installed packages to a list

The first step in creating a re-installation script for Fedora Linux is to get a list of all the installed packages on the system. The best way to generate a simple package list on Fedora is with the rpm system.

To generate a simple package list in Fedora, open up a terminal window by pressing Ctrl + Alt + T or Ctrl + Shift + T on the keyboard. From there, use the rpm command below to print out a list of all the installed apps on your Fedora Linux PC.

rpm -qa | sort

The package output is extensive, and it has every single thing that has ever been installed on your Fedora Linux system. However, just the list as is doesn’t help. It needs to be piped into a text file for editing purposes. Take the rpm command above and add a > symbol to pipe it through to a text file in the home directory.

rpm -qa | sort > ~/pkgs.txt

From here, open up the Linux file manager on your Fedora PC, and right-click on ‘pkgs.txt’ to edit it with your text editor of choice. Go through the list of packages and remove any you don’t want. When done, move on to the next section of the guide.

Generate a re-installation script for Fedora

Now that all installed Fedora Linux packages are saved to an editable text file, we can use it to start creating the re-installation script. Follow the step-by-step instructions below to generate a Fedora re-install script.

WARNING: this script will fail if you attempt to install programs on Fedora from third-party software repositories if they’re not enabled. To prevent it from failing to install everything, be sure to enable all third-party software sources first.

Step 1: Use the touch command to create a blank SH file with the name of “fedora-app-re-installer.sh.”

touch ~/fedora-app-re-installer.sh

Step 2: Using the echo command, add the script shebang to the top of the file, so that the interpreter can understand how to run this script.

echo '#!/bin/bash' > fedora-app-re-installer.sh

Step 3: Add a blank line to the script so that the commands aren’t jumbled at the top near the first line with the echo command.

echo ' ' >> fedora-app-re-installer.sh

Step 4: Add the $pkgs variable to the script using the echo command.

echo 'pkgs="' >> fedora-app-re-installer.sh

Step 5: Define the $pkgs variable with the contents of the “pkgs.txt” file in your home directory that was generated earlier using the rpm command.

cat pkgs.txt >> fedora-app-re-installer.sh

Step 6: Close the $pkgs variable line off with the echo command.

echo '"' >> fedora-app-re-installer.sh

Step 7: Following the $pkgs variable, add a new line to the file.

echo ' ' >> fedora-app-re-installer.sh

Step 8: Add in the installation code, so that when the script is run on a Fedora Linux PC, it’ll automatically start installing all of the programs specified from various software repositories.

If you plan to run the reinstallation script on a fresh Fedora Linux PC, and none of the packages on the list are installed, enter the command below.

echo 'sudo dnf install $pkgs' >> fedora-app-re-installer.sh

Alternatively, if these packages are already on the system, but you want to reload all of them, try using the “reinstall” option instead.

echo 'sudo dnf reinstall $pkgs' >> fedora-app-re-installer.sh

Step 9: Using the chmod command, update the permissions of the script file. Updating permissions is critical, as it will allow the script to execute itself as a program from any Fedora Linux terminal window.

sudo chmod +x fedora-app-re-installer.sh

With the permissions up to date, the script is ready to run. Feel free to re-do the steps in this process if you’d like to add (or remove) programs from the list.

Running the script

So, the re-installation script for your Fedora Linux PC is written and ready to go. Now, all there is to do is to run it as a program, so that it can re-install all of your programs. To run the re-installation script on Fedora, open up a terminal window. Once the terminal window is open, gain root access in the home directory where the script file is with the sudo -s command.

sudo -s

From there, run the re-installation script with the command below.

./fedora-app-re-installer.sh

Don’t want to log into the root account to run the script? Try executing it with the following command instead.

sudo ./fedora-app-re-installer.sh

2 Comments

  1. * You don’t need to touch the file before echoing its first line
    * The first step creates a file in ~ (home directory) but then the rest of the instructions omit it, so they assume you’re working in your home directory or you wind up creating a second file in whatever directory you’re in.
    * With the -e option to echo, you can insert a newline in output with \n, so the first three steps become
    echo -e ‘#!/bin/bash\npkgs=”‘ > ~/fedora-app-re-installer.sh
    * You don’t need `sudo` to run chmod on a script that you created.
    * It’s a bad idea to start a shell running as root (`sudo -s`), you can easily forget you’re in a root shell and will create files owned by root that you can’t alter, or worse run a command that is even more destructive when run as root.
    * The only step in the script that requires root permissions is the `dnf` command, but that is already using sudo. So there’s no reason to run the script as root; just run the script and the `sudo dnf` line will prompt “[sudo] password for :”