Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install or uninstall a package listed in a file on Linux

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to install or uninstall a software package listed in a file on Linux". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to install or uninstall a package listed in a file on Linux".

In some cases, you may want to install a list of packages from one server to another. For example, you have installed 15 packages on server An and these packages need to be installed on server B, server C, and so on.

We can install the software manually, but it will take a lot of time. You can install one or two servers manually, but imagine if you have about ten servers. In this case, you can't finish the work manually, so how can you solve the problem?

Don't worry. We can help you get out of this situation and situation. We have added four ways to overcome the difficulties in this article.

I hope this will help you solve the problem. I have tested these commands on Centos7 and Ubuntu 18.04.

I hope this works on other distributions, too. All you need to do is replace the package manager command in this article with the official package manager command for that release.

If you want to check the list of packages installed on the Linux system, click the link.

For example, if you want to create a package list on a RHEL-based system, use the following steps. The same is true of other distributions.

# rpm-qa-- last | head-15 | awk'{print $1}'> / tmp/pack1.txt # cat / tmp/pack1.txtmariadb-server-5.5.60-1.el7_5.x86_64perl-DBI-1.627-4.el7.x86_64perl-DBD-MySQL-4.023-6.el7.x86_64perl-PlRPC-0.2020-14.el7.noarchperl-Net-Daemon-0.48-5.el7.noarchperl-IO-Compress-2.061-2.el7 .noarchperl-Compress-Raw-Zlib-2.061-4.el7.x86_64mariadb-5.5.60-1.el7_5.x86_64perl-Data-Dumper-2.145-3.el7.x86_64perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64httpd-2.4.6-88.el7.centos.x86_64mailcap-2.1.41-2.el7.noarchhttpd-tools-2.4.6-88.el7.centos.x86_64apr-util-1 .5.2-6.el7.x86_64apr-1.4.8-3.el7_4.1.x86_64 method 1: how to use the cat command on Linux to install the packages listed in the file?

To achieve this goal, I will use a simple and straightforward method. To do this, create a file and add a list of packages you want to install.

For testing purposes, we will only add the following three package names to the file.

# cat / tmp/pack1.txt apache2mariadb-servernano

You can install all the software packages on the Ubuntu/Debian system at once by simply running the apt command.

# apt-y install $(cat / tmp/pack1.txt) Reading package lists... DoneBuilding dependency treeReading state information... DoneThe following packages were automatically installed and are no longer required: libopts25 sntpUse 'sudo apt autoremove' toremove them.Suggested packages: apache2-doc apache2-suexec-pristine | apache2-suexec-custom spellThe following NEW packages will be installed: apache2 mariadb-server nano0 upgraded, 3 newly installed, 0 toremove and 24 not upgraded.Need to get 339 kB of archives.After this operation 1377 kB of additional disk space will be used.Get:1 http://in.archive.ubuntu.com/ubuntu bionic-updates/main amd64 apache2 amd64 2.4.29-1ubuntu4.6 [95.1 kB] Get:2 http://in.archive.ubuntu.com/ubuntu bionic/main amd64 nano amd64 2.9.3-2 [231 kB] Get:3 http://in.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 mariadb-server all 1 Get:3 10.1.38-0ubuntu0.18. 04.1 [12.9 kB] Fetched 339 kB in 19s (18.0 kB/s) Selecting previously unselected package apache2. (Reading database... 290926 files and directories currently installed.) Preparing to unpack... / apache2_2.4.29-1ubuntu4.6_amd64.deb... Unpacking apache2 (2.4.29-1ubuntu4.6)... Selecting previously unselected package nano.Preparing to unpack... / nano_2.9.3-2_amd64.deb... Unpacking nano (2.9. 3-2)... Selecting previously unselected package mariadb-server.Preparing to unpack... / mariadb-server_1%3a10.1.38-0ubuntu0.18.04.1_all.deb... Unpacking mariadb-server (1Selecting previously unselected package mariadb-server.Preparing to unpack 10.1.38-0ubuntu0.18.04.1)... Processing triggers for ufw (0.36-0ubuntu0.18.04.1)... Setting up apache2 (2.4.29-1ubuntu4.6)... Processing triggers for ureadahead (0. 100.0-20)... Processing triggers for install-info (6.5.0.dfsg.1-2)... Setting up nano (2.9.3-2)... update-alternatives: using / bin/nano to provide / usr/bin/editor (editor) in auto modeupdate-alternatives: using / bin/nano to provide / usr/bin/pico (pico) in auto modeProcessing triggers for systemd (237-3ubuntu10.20)... Processing triggers for man-db (2.8.3) -2ubuntu0.1)... Setting up mariadb-server (1VR 10.1.38-0ubuntu0.18.04.1)...

As for deletion, you need to use the same command format and appropriate options.

# apt-y remove $(cat / tmp/pack1.txt) Reading package lists... DoneBuilding dependency treeReading state information... DoneThe following packages were automatically installed and are no longer required: apache2-bin apache2-data apache2-utils galera-3 libaio1 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl libjemalloc1 liblua5.2-0 libmysqlclient20 libopts25 libterm-readkey-perl mariadb-client-10.1 mariadb-client-core-10.1 mariadb-common mariadb-server-10.1 mariadb-server-core-10.1 mysql-common sntp socatUse 'apt autoremove' toremove them.The following packages will be REMOVED: apache2 mariadb-server nano0 upgraded, 0 newly installed 3 to remove and 24 not upgraded.After this operation 1377 kB disk space will be freed. (Reading database... 291046 files and directories currently installed.) Removing apache2 (2.4.29-1ubuntu4.6)... Removing mariadb-server (1files and directories currently installed 10.1.38-0ubuntu0.18.04.1)... Removing nano (2.9.3-2)... update-alternatives: using / usr/bin/vim.tiny to provide / usr/bin/editor (editor) in auto modeProcessing triggers for ufw (0.36-0ubuntu0.18.04. 1)... Processing triggers for install-info (6.5.0.dfsg.1-2)... Processing triggers for man-db (2.8.3-2ubuntu0.1).

Use the yum command to install the packages listed in the files on RHEL-based systems such as Centos, RHEL (Redhat), and OEL (Oracle Enterprise Linux).

# yum-y install $(cat / tmp/pack1.txt)

Use the command to uninstall the packages listed in the file on RHEL-based systems such as Centos, RHEL (Redhat), and OEL (Oracle Enterprise Linux).

# yum-y remove $(cat / tmp/pack1.txt)

Use the following dnf command to install the packages listed in the file on the Fedora system.

# dnf-y install $(cat / tmp/pack1.txt)

Use the following command to uninstall the packages listed in the file on the Fedora system.

# dnf-y remove $(cat / tmp/pack1.txt)

Use the following zypper command to install the packages listed in the file on the openSUSE system.

# zypper-y install $(cat / tmp/pack1.txt)

Use the following command to uninstall the packages listed in the file from the openSUSE system.

# zypper-y remove $(cat / tmp/pack1.txt)

Use the following pacman command to install the packages listed in the files on Arch Linux-based systems such as Manjaro and Antergos.

# pacman-S $(cat / tmp/pack1.txt)

Use the following command to uninstall the packages listed in the file from Arch Linux-based systems such as Manjaro and Antergos.

# pacman-Rs $(cat / tmp/pack1.txt) method 2: how to install the packages listed in the file in Linux using the cat and xargs commands.

I even prefer to use this method because it is a very simple and straightforward method.

Use the following apt command to install the packages listed in the file on Debian-based systems such as Debian, Ubuntu, and Linux Mint.

# cat / tmp/pack1.txt | xargs apt-y install

Use the following apt command to uninstall the packages listed in the file from Debian-based systems such as Debian, Ubuntu, and Linux Mint.

# cat / tmp/pack1.txt | xargs apt-y remove

Use the following yum command to install the packages listed in the files on RHEL-based systems such as Centos,RHEL (Redhat) and OEL (Oracle Enterprise Linux).

# cat / tmp/pack1.txt | xargs yum-y install

Use the command to uninstall the packages listed in the file from RHEL-based systems such as Centos, RHEL (Redhat), and OEL (Oracle Enterprise Linux).

# cat / tmp/pack1.txt | xargs yum-y remove

Use the following dnf command to install the packages listed in the file on the Fedora system.

# cat / tmp/pack1.txt | xargs dnf-y install

Use the following command to uninstall the packages listed in the file from the Fedora system.

# cat / tmp/pack1.txt | xargs dnf-y remove

Use the following zypper command to install the packages listed in the file on the openSUSE system.

# cat / tmp/pack1.txt | xargs zypper-y install

Use the following command to uninstall the packages listed in the file from the openSUSE system.

# cat / tmp/pack1.txt | xargs zypper-y remove

Use the following pacman command to install the packages listed in the files on Arch Linux-based systems such as Manjaro and Antergos.

# cat / tmp/pack1.txt | xargs pacman-S

Use the following command to uninstall the packages listed in the file from Arch Linux-based systems such as Manjaro and Antergos.

# cat / tmp/pack1.txt | xargs pacman-Rs method 3: how to install the software package listed in the file on Linux using the For loop

We can also use the for loop command to do this.

The following command for a for loop can be used to install bulk packages.

# for pack in `cat / tmp/ pack 1.txt`; do apt-y install $I; done

To install bulk packages using the shell script, use the following for loop.

# vi / opt/scripts/bulk-package-install.sh #! / bin/bashfor pack in `cat / tmp/ pack 1.txt`do apt-y remove $packdone

Set executable permissions for bulk-package-install.sh.

# chmod + bulk-package-install.sh

Run this script.

# sh bulk-package-install.sh method 4: how to use the While loop to install the software package listed in the file on Linux

We can also use the while loop command to achieve this.

The following command for a while loop can be used to install bulk packages.

# file= "/ tmp/pack1.txt"; while read-r pack; do apt-y install $pack; done < "$file"

To install bulk packages using the shell script, use the following while loop.

# vi / opt/scripts/bulk-package-install.sh #! / bin/bashfile= "/ tmp/pack1.txt" while read-r packdo apt-y remove $packdone < "$file"

Set executable permissions for bulk-package-install.sh.

# chmod + bulk-package-install.sh

Run this script.

# sh bulk-package-install.sh Thank you for reading, the above is the content of "how to install or uninstall a software package listed in a file on Linux". After the study of this article, I believe you have a deeper understanding of how to install or uninstall a software package listed in a file on Linux, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report