bulk packages installation install package install packages from a file Linux Advanced Commands Package Installation Package Management package manager shell script uninstall bulk packages

How To Install/Uninstall Listed Packages From A File In Linux?

In some case chances are you’ll need to install record of packages from one server to a different server.

For instance, You’ve gotten put in 15 packages on ServerA, and people packages must be put in on ServerB, ServerC, and so on.,

We will manually install all the packages however it’s time consuming course of.

It can be completed for one or two servers, think about when you have round 10 servers.

In this case it doesn’t provide help to then What will be the answer?

Don’t worry we are right here that will help you out on this state of affairs or state of affairs.

We have now added four methods in this article to beat this example.

I hope this can show you how to to repair your difficulty. I have examined these instructions on CentOS7 and Ubuntu 18.04 methods.

I hope this can work with other distributions too. Just exchange with distribution official package deal manager command as an alternative of us.

Navigate to the following article if you want to examine record of installed packages in Linux system.

For instance, if you need to create a package deal lists from RHEL based mostly system then use the following steps. Do the same for different distributions as nicely.

# rpm -qa –final | head -15 | awk ‘print $1’ > /tmp/pack1.txt

# cat /tmp/pack1.txt
mariadb-server-5.5.60-1.el7_5.x86_64
perl-DBI-1.627-4.el7.x86_64
perl-DBD-MySQL-4.023-6.el7.x86_64
perl-PlRPC-0.2020-14.el7.noarch
perl-Internet-Daemon-Zero.48-5.el7.noarch
perl-IO-Compress-2.061-2.el7.noarch
perl-Compress-Raw-Zlib-2.061-4.el7.x86_64
mariadb-5.5.60-1.el7_5.x86_64
perl-Knowledge-Dumper-2.145-3.el7.x86_64
perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64
httpd-2.Four.6-88.el7.centos.x86_64
mailcap-2.1.41-2.el7.noarch
httpd-tools-2.4.6-88.el7.centos.x86_64
apr-util-1.5.2-6.el7.x86_64
apr-1.4.8-3.el7_4.1.x86_64

Technique-1 : How To Set up Listed Packages From A File In Linux With Assist Of cat Command?

To achieve this, i want to go together with this primary technique. As this very simple and easy.

To achieve this, just create a file and add the record of packages that you simply need to set up it.

For testing objective, we’re going to add only the under three packages into the next file.

# cat /tmp/pack1.txt

apache2
mariadb-server
nano

Simply run the following apt command to install all the packages in a single shot from a file in Ubuntu/Debian methods.

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

Reading package deal lists… Executed
Constructing dependency tree
Reading state info… Accomplished
The next packages have been mechanically put in and are not required:
libopts25 sntp
Use ‘sudo apt autoremove’ to take away them.
Steered packages:
apache2-doc apache2-suexec-pristine | apache2-suexec-custom spell
The next NEW packages can be installed:
apache2 mariadb-server nano
0 upgraded, 3 newly put in, 0 to take away and 24 not upgraded.
Have to get 339 kB of archives.
After this operation, 1,377 kB of further disk area will probably be used.
Get:1 http://in.archive.ubuntu.com/ubuntu bionic-updates/major amd64 apache2 amd64 2.4.29-1ubuntu4.6 [95.1 kB] Get:2 http://in.archive.ubuntu.com/ubuntu bionic/principal 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:10.1.38-0ubuntu0.18.04.1 [12.9 kB] Fetched 339 kB in 19s (18.Zero kB/s)
Choosing previously unselected package deal apache2.
(Reading database … 290926 information and directories presently installed.)
Getting ready to unpack …/apache2_2.4.29-1ubuntu4.6_amd64.deb …
Unpacking apache2 (2.Four.29-1ubuntu4.6) …
Choosing previously unselected package deal nano.
Getting ready to unpack …/nano_2.9.3-2_amd64.deb …
Unpacking nano (2.9.Three-2) …
Choosing previously unselected package deal mariadb-server.
Getting ready to unpack …/mariadb-server_1percent3a10.1.38-0ubuntu0.18.04.1_all.deb …
Unpacking mariadb-server (1:10.1.38-0ubuntu0.18.04.1) …
Processing triggers for ufw (0.36-0ubuntu0.18.04.1) …
Establishing apache2 (2.Four.29-1ubuntu4.6) …
Processing triggers for ureadahead (0.100.Zero-20) …
Processing triggers for install-info (6.5.0.dfsg.1-2) …
Establishing nano (2.9.3-2) …
update-alternatives: utilizing /bin/nano to offer /usr/bin/editor (editor) in auto mode
update-alternatives: using /bin/nano to offer /usr/bin/pico (pico) in auto mode
Processing triggers for systemd (237-3ubuntu10.20) …
Processing triggers for man-db (2.Eight.Three-2ubuntu0.1) …
Establishing mariadb-server (1:10.1.38-0ubuntu0.18.04.1) …

For removing, use the identical format with applicable choice.

# apt -y remove $(cat /tmp/pack1.txt)
Reading package deal lists… Completed
Building dependency tree
Reading state info… Completed
The next packages have been routinely installed and are not 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 socat
Use ‘apt autoremove’ to take away them.
The next packages shall be REMOVED:
apache2 mariadb-server nano
Zero upgraded, Zero newly put in, 3 to take away and 24 not upgraded.
After this operation, 1,377 kB disk area shall be freed.
(Reading database … 291046 information and directories at present installed.)
Eradicating apache2 (2.Four.29-1ubuntu4.6) …
Eradicating mariadb-server (1:10.1.38-0ubuntu0.18.04.1) …
Removing nano (2.9.3-2) …
update-alternatives: using /usr/bin/vim.tiny to offer /usr/bin/editor (editor) in auto mode
Processing triggers for ufw (0.36-0ubuntu0.18.04.1) …
Processing triggers for install-info (6.5.Zero.dfsg.1-2) …
Processing triggers for man-db (2.8.3-2ubuntu0.1) …

Use the following yum command to install listed packages from a file on RHEL based mostly methods corresponding to CentOS, RHEL (Redhat) and OEL (Oracle Enterprise Linux).

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

Use the next format to uninstall listed packages from a file on RHEL based mostly techniques comparable to CentOS, RHEL (Redhat) and OEL (Oracle Enterprise Linux).

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

Use the next dnf command to put in listed packages from a file on Fedora system.

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

Use the following format to uninstall listed packages from a file on Fedora system.

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

Use the following zypper command to put in listed packages from a file on openSUSE system.

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

Use the next format to uninstall listed packages from a file on openSUSE system.

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

Use the next pacman command to put in listed packages from a file on Arch Linux based mostly methods resembling Manjaro and Antergos system.

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

Use the next format to uninstall listed packages from a file on Arch Linux based mostly techniques corresponding to Manjaro and Antergos system.

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

Technique-2 : How To Set up Listed Packages From A File In Linux With Help Of cat And xargs Command?

Even, i choose to go together with this technique as a result of this is very simple and easy technique.

Use the following apt command to install listed packages from a file on Debian based mostly techniques akin to Debian, Ubuntu and Linux Mint.

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

Use the next apt command to uninstall listed packages from a file on Debian based mostly methods comparable to Debian, Ubuntu and Linux Mint.

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

Use the next yum command to put in listed packages from a file on RHEL based mostly methods reminiscent of CentOS, RHEL (Redhat) and OEL (Oracle Enterprise Linux).

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

Use the next format to uninstall listed packages from a file on RHEL based mostly methods comparable to CentOS, RHEL (Redhat) and OEL (Oracle Enterprise Linux).

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

Use the next dnf command to put in listed packages from a file on Fedora system.

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

Use the following format to uninstall listed packages from a file on Fedora system.

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

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

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

Use the next format to uninstall listed packages from a file on openSUSE system.

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

Use the next pacman command to put in listed packages from a file on Arch Linux based mostly techniques resembling Manjaro and Antergos system.

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

Use the following format to uninstall listed packages from a file on Arch Linux based mostly techniques akin to Manjaro and Antergos system.

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

Technique-3 : How To Set up Listed Packages From A File In Linux With Assist Of For Loop Command?

Alternatively we will use the “For Loop” command to realize this.

To set up bulk packages. Use the under format to run a “For Loop” with single line.

# for pack in `cat /tmp/pack1.txt` ; do apt -y install $i; accomplished

To set up bulk packages with shell script use the next “For Loop”.

# vi /choose/scripts/bulk-package-install.sh

#!/bin/bash
for pack in `cat /tmp/pack1.txt`
do apt -y remove $pack
carried out

Set an executable permission to bulk-package-install.sh file.

# chmod + bulk-package-install.sh

Finally run the script to realize this.

# sh bulk-package-install.sh

Technique-4 : How To Set up Listed Packages From A File In Linux With Assist Of While Loop Command?

Alternatively we will use the “While Loop” command to realize this.

To set up bulk packages. Use the under format to run a “While Loop” with single line.

# file=”/tmp/pack1.txt”; whereas read -r pack; do apt -y install $pack; finished

To install bulk packages with shell script use the following “While Loop”.

# vi /choose/scripts/bulk-package-install.sh

#!/bin/bash
file=”/tmp/pack1.txt”
while learn -r pack
do apt -y remove $pack
carried out

Set an executable permission to bulk-package-install.sh file.

# chmod + bulk-package-install.sh

Lastly run the script to realize this.

# sh bulk-package-install.sh