Reinstall All Packages with Pacman on Arch Linux

Chưa phân loại
At times you may need to reinstall all the packages on your Arch Linux.

Let’s say you have Arch Linux installed on your machine and it is fully functional. No problem here. Now imagine, you are playing with your Arch Linux system and accidentally deleted some of the system files and folders. You’re freaked out saying, ‘Oh no! I shouldn’t have played God with sudo’. Don’t freak out just yet. There may still be a chance you can fix that using Pacman.  You can use Pacman package manager to reinstall all the system packages on your Arch Linux machine.

Another scenario may be, let’s say you did a full system upgrade. Everything went well. But once you reboot your system, it won’t start and you’re getting warnings that some files are missing. This can also be fixed by reinstalling all the packages on your Arch Linux machine.

In this article, I will show you how to reinstall all the packages with Pacman on Arch Linux. Let’s get started.

Reinstallation Fixes Missing Files

In this section I will delete some files from /usr/bin and recover them by reinstalling the package to show you that reinstalling fixes issues related to missing files or corrupted files.

I am going to run the following command to remove all the grub related binary files:

$ rm -rfv /usr/bin/grub-*

As you can see in the screenshot below, the files are removed.

Now I am going to reinstall the grub package with the following command:

$ pacman -S –force –noconfirm grub

The grub package is reinstalled.

Now let’s do a ls -la grub-*, and as you can see in the screenshot below, the removed files are back.

So reinstalling packages can recover broken Arch Linux systems.

Creating a Script for Reinstalling All the Packages

I am not going to reinstall packages one by one. Instead, I will write a bash script to do that automatically.

First create a new directory recovery/ with the following command:

$ mkdir recovery

Now navigate to the newly created directory with the following command:

$ cd recovery

Now export all the package names that are installed on your Arch Linux system with the following command:

$ pacman -Qq > packages.txt

Now create a new shell script with the following command:

$ nano

An empty file should be opened in nano text editor.

Now add these lines to the file:

for pkgName in $(cat packages.txt

  pacman -S –force –noconfirm $pkgName
echo "Reinstalled all packages."

Now press <Ctrl> + x and then press y and then press <Enter> to save the file.

Now make the script executable with the following command:

$ chmod +x

Reinstalling All the Packages When You Can Boot Into your Arch Linux System

If you can boot into your Arch Linux machine, then it’s really easy to reinstall all the packages with Pacman package manager with the script I created earlier.

First navigate to the recovery/ directory:

$ cd recovery/

Now run the script as follows:

$ ./

As you can see, packages are being reinstalled.

It should take a long time to completed depending on your internet connection.

Reinstalling All the Packages When You Can’t Boot into Your Arch Linux System

If you fail to boot into your Arch Linux system, then grab an Arch Linux installation CD and boot into it.

Once you boot into your Arch Linux installer CD, connect to the internet. If you’re using a wired connection and your network is configured with DHCP, then all you have to do is run the following command:

$ dhclient -v

Then you have to mount the Root and Boot (also EFI partition if you’re using GPT partition table) partition of your broken Arch Linux to /mnt directory. My Root partition is /dev/sda3, Boot partition is /dev/sda2, and EFI partition is /dev/sda1.

Mount these partitions to /mnt with the following commands:

$ mount /dev/sda3 /mnt
$ mount /dev/sda2 /mnt
$ mount /dev/sda3 /mnt

Now Chroot into /mnt directory.

Navigate to your recovery/ directory and execute the reinstall script. If you weren’t able to create these, then you should be able to follow Creating a Script for Reinstalling All the Packages section of this article and create it now.

$ cd /root/recovery

$ ./

The package reinstallation process should start as you can see in the screenshot below.

Once the reinstallation is complete, run the following command to exit out of Chroot:

$ exit

Then reboot your computer. Your problem should be solved.

That’s how you reinstall all the packages of Arch Linux with Pacman. Thanks for reading this article.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Setup NAS Server on Raspberry Pi 3

NAS servers are really costly these days. If you don’t have that much money to spare, then you use Raspberry Pi 3 to set...

How to do data recovery from hard drive

This tutorial shows how to recover data from storage devices in Linux. In this case the data will be recovered from a SanDisk...

Python: Vectors, Matrices and Arrays with NumPy

In this lesson, we will look at some neat tips and tricks to play with vectors, matrices and arrays using NumPy library...