How to Install RPM Packages From Text File [5 Simple Cases]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

Package management in a Linux/Unix system is a common task, but managing a long list of packages for installation can be cumbersome. If you have a text file with numerous RPM packages, manually entering each package’s name for installation is tiresome and error-prone. Fortunately, there are efficient ways to automate this process, especially when you have a list of package names stored in a text file. In this detailed guide, I will show you 5 efficient methods to install rpm packages from a text file in any Red Hat-based Linux distribution like RHEL, CentOS, Fedora, etc.

If you want to install an individual RPM file, then use the following command:

  1. Using rpm command: rpm -i [package_name]
  2. Using yum command: yum install [package_name]
  3. Using dnf command: dnf install [package_name]

Process Flow Chart to Install RPM Packages from Text File

step by step of installing rpm packages from text file using dnf/yum package manager in Red Hat based distributions using command line interface (CLI)[Distro Used Throughout the Tutorial: RHEL 9.2]

5 Cases to Install RPM Packages From a Text File

There are 3 primary package managers in the Red Hat-based system: RPM (Red Hat Package Manager), YUM (Yellowdog Updater Modified), and DNF (Dandified YUM). Yum is built on top of the rpm package manager to offer an array of features that go beyond the basic rpm. DNF builds upon the legacy of YUM and offers more advanced capabilities. In this guide, I will dive into the process of installing packages from a text file. I will be using the dnf package manager in this article as it is the latest package manager for the Red Hat-based system.

Note: Both yum or dnf package managers can be used for installing packages from a text file as they both can automatically handle dependency and can download and install app packages from remote repositories. The rpm package manager only supports local installation, so you can not use it for this task.

If you want to know how to install app packages using yum, check this detailed article on “How to Install RPM Packages Using YUM”. To install a local package using dnf check “How to Install Local Package Using DNF

Case 01: Install RPM Packages From a Text File Using the Command Substitution

Using the command substitution$(command)” is the easiest way to install rpm packages from a text file. This helps to read the package names from the text file and pass them as an argument to the “dnf install” command which can automatically download and install all packages from the remote repositories. Here’s how:

  1. Before starting, make sure that you have a text file containing the list of rpm packages you want to install and that the package names are in proper order in the text file. In order to check this first open your terminal.

  2. Next, move to the directory where the file is located using the following command:

    cd Downloads/
    EXPLANATION
    • cd: Changes the current directory to the destination directory.
    • Downloads/: Name of the destination directory.

    change directory to the location of the text file and view all files and folders of that directory

  3. After that, run the following command to confirm that your desired text file is present in that directory:

    ls
    EXPLANATION
    • ls: List all files and folders of the current directory in the command line.

    view the contents of the text file

  4. Now, execute the following command to check the content of the text file. It will look similar to the above image.

    cat packages.txt
    EXPLANATION
    • cat: Displays the contents of one or more files to the terminal.
    • txt: Name of the text file that contains the list of package names that need to be installed.
  5. Now, run the following command to install all rpm app packages from the text file. It will look similar to the following image.

    sudo dnf install -y $(cat packages.txt)
    EXPLANATION
    • sudo: Permits administrative permission.
    • dnf: Package manager in Red Hat-based distributions.
    • install: Install an app package using dnf.
    • y: Confirm the installation of packages without asking for user confirmation.
    • $() [Command Substitution]: Read the text file and pass them as arguments to the dnf install command.

    install rpm app packages from text file using Command Substitution

    After running this, the system will prompt you to enter your sudo user password, as indicated in the image above. Provide your sudo password.

  6. Then, the system will automatically download and install all the app packages listed in the text file.

    packages installation complete

    Finally, upon successful installation, your system will display a confirmation message like the image above. By following these simple step-by-step instructions, you have successfully installed a list of packages from a text file using the “dnf install” command.

    If you want to verify the installation status of a specific package check “How to Check if Package is Installed Using YUM”.

Case 02: Install RPM Packages Efficiently From Text File Using “xargs” Command

In the world of Linux/Unix systems, efficiency is key. When dealing with a large number of package installations, the “xargs” command comes to the rescue, allowing to streamline this process.

This command is a powerful utility that reads items from standard input (in this case, the contents of the text file) and executes a command with those items as arguments. This makes it perfect for efficiently handling lists of package names in a text file and passing them to a package manager like dnf for installation. Below is a step-by-step guide:

  1. Run the following command to install all app packages from the text file using the “xargs” command. It will look similar as shown in the following image.

    cat packages.txt | xargs sudo dnf -y install
    EXPLANATION
    • | (pipe): Pipe is used to redirect the standard output.
    • xargs: Read the input from the previous command and pass them as arguments to the subsequent command.

    install rpm app packages from text file using “xargs” Command

    After running this you will be prompted to enter your sudo user password as shown in the above image. Provide your sudo password.

    rpm packages installation complete

  2. Then, all the application packages listed in the text file will be automatically fetched and installed. Once the installation is successful, your system will present a confirmation message, similar to the one shown in the image above.

Case 03: Install RPM Packages Using a Bash Loop

In this method, I will utilize a Bash loop to streamline the installation of RPM packages listed in a text file. This approach is effective when you want to have precise control over the installation process and when you wish to monitor each package as it installs. To install rpm app packages from a text file follow these step-by-step processes:

  1. Now, run the following command to install all app packages from the text file using bash loop. It will look as shown in the following image.

    for i in `cat packages.txt` ; do sudo dnf -y install $i; done
    EXPLANATION
    • for: Start a bash loop.
    • i: Loop iterator.
    • in: Specify the list of items that the loop will iterate over.
    • ` `: Read the continent of the text file to iterate over.
    • do: Mark the beginning of the code block that will be executed for each item in the list.
    • $i: Takes the value of the current package name, allowing DNF to install that specific package, during each iteration of the loop.
    • done: Marks the end of the code block that is executed for each item in the list.

    install rpm app packages from text file using a Bash Loop

    After running this command, the system will prompt you to enter your sudo user password, as shown in the image above. Provide your sudo password.

    1st package installation complete, 2nd package installation started

  2. Then, the system will automatically download and install each of the application packages listed in the text file sequentially. After installation of each package is completed, the system will display a confirmation message, as shown in the image above, and then proceed to install the next package.

Case 04: RPM Packages Installation Using “stdin” Redirection

In this case, I will explore a method that involves using “stdin” redirection combined with the “xargs” command to install RPM packages from a text file. This approach is particularly efficient and is a great addition to your Linux toolbox. To install app packages from a text file follow these instructions:

  1. Now, execute this command to install all app packages from the text file. It will look as shown in the following image.

    xargs sudo dnf -y install < packages.txt
    EXPLANATION
    • <: stdin redirection.

    Once you execute the command, the system will prompt you to enter your sudo user password, as shown in the following image. Please provide your sudo password.

    install rpm app packages from text file using “stdin” Redirection

    packages installation complete

  2. Then, the system will automatically fetch and install all the application packages listed in the text file. Upon successful installation of all the packages, you will receive a confirmation message in your terminal.

Case 05: RPM Packages Installation Using Space Translation

In this case, I will explore an interesting approach to installing RPM packages listed in a text file using the translate (“tr‘”) command. This method is a bit different from the previous ones I have covered, as it involves translating newline characters to spaces. This results in a single command that efficiently installs all the specified packages from the text file. I will now dive in and show how it’s done:

  1. Now, execute this command to install all app packages from the text file. It will look as shown in the following image.

    sudo dnf -y install `cat packages.txt | tr '\n' ' '`
    EXPLANATION
    • tr ‘\n’ ‘ ‘: Translate the newlines into spaces, effectively creating a single line with package names.

    install rpm app packages from text file using Space Translation

    After you execute the command, it will prompt you to enter your sudo user password for authentication. Please provide your sudo password to proceed with the installation.

    rpm packages installation complete

  2. The system will begin installing the RPM packages one by one. You’ll see the progress as each package is downloaded and installed. Depending on the number and size of the packages, this process may take some time. After successfully installing all packages, the terminal will display a confirmation message similar to the image above.

Conclusion

In conclusion, in this guide, I have illuminated five efficient methods for simplifying the process of installing RPM packages from a text file in Red Hat-based Linux distributions. Whether you prefer command substitution, xargs, bash loops, stdin redirection, or space translation, you now possess a diverse toolkit to streamline package management.

People Also Ask

How to download RPM package without installing?

To download an RPM package without installing it, you can use the “dnf download package-name” command. It will retrieve the RPM file without installing it, allowing you to save it for later use or inspection.

How to install software using dnf?

To install software using DNF (Dandified YUM), open the terminal and run “sudo dnf install <package-name>“. DNF will automatically resolve dependencies and will download and install the package. This simple command streamlines software installation on Red Hat-based Linux systems.

How to open an rpm file in Linux?

To open a file in Linux with .rpm extension, open the terminal and run the command rpm2cpio <.rpm_file> | cpio -idmv. Replace <.rpm_file> with the rpm file you want to open. This rpm2cpio utility lets open the specified rpm file without installation.

How can we install RPM package using yum?

To install an RPM package using YUM, you can run the yum install package.rpm command for local installation or the yum install package-name command for online installation. It will initiate the installation process, handling dependencies and configuring the software for your system.

How to remove a RPM package?

To remove a RPM package, use the rpm command with the -e option. Open the terminal and run the command sudo rpm -e and the package_name afterward to remove the package from the system. For instance, running the command sudo rpm -e Firefox removes the package Firefox.

How to install local file with yum?

To install a local package in any Red Hat-based Linux system using yum, first move to the download folder using cd Download/ then run sudo yum localinstall filename.rpm or you can just run sudo yum localinstall path/filename.rpm in the terminal. It will install the local package in your system using the Yum package manager.

How to install a RPM package using the command line?

To install an RPM package using the command line, type the command sudo rpm -i sample_package.rpm and press ENTER. The<strong> -i</strong> flag tells the rpm command to install the given package sample_package.rpm.

Related Articles


<< Go Back to Package Installation in Linux | Package Management in Linux | Learn Linux Basics

4.8/5 - (16 votes)
Ridoy Chandra Shil

Hello everyone. I am Ridoy Chandra Shil, currently working as a Linux Content Developer Executive at SOFTEKO. I am a Biomedical Engineering graduate from Bangladesh University of Engineering and Technology. I am a science and tech enthusiast. In my free time, I read articles about new tech and watch documentaries on science-related topics. I am also a big fan of “The Big Bang Theory”. Read Full Bio

Leave a Comment