Pacman command in Arch Linux

21 Dec, 2021
Pacman is a package manager for the arch Linux and arch-based Linux distributions. If you have used Debian-based OS like ubuntu, then the  Pacman is similar to the apt command of Debian-based operating systems. Pacman contains the compressed files as a package format and maintains a text-based package database. Pacman keeps the system up to date by synchronizing package lists with the master server. Pacman can install the packages from the official repositories or your own build packages.
In this article, we are going to see how to use Pacman to manage the software in arch-based systems. Now let’s see how to use Pacman.
When we install any new operating system on our machine, the first task we do is to install the software packages on the system. Now, to install the packages on Arch Linux, use the command Pacman with -S option and mention the package name. The -S option tells the Pacman to synchronize and to continue. Here is one example 
sudo pacman -S cmatrix
We can mention the many package names after the -S option, separated by space.
sudo pacman -S package1 package2 package3
Then Pacman will show the download and install size of the package and ask for to proceed, then simply press the Y key. Pacman categorizes the installed packages into two categories.
Implicitly Installed: The package that was installed using the -S or -U option.
Dependencies: The package is installed because it is required by another package.
Now let’s see how to remove the installed package.
When we don’t need the package anymore, then we should remove the package from the system. To remove the package with all its dependencies which are not required by other packages, use the following command:
sudo pacman -Rs <package_name>
To remove the package without removing its dependency use the following command:
sudo pacman -R <package_name>
To remove the dependencies which are not required anymore, use the following command:
pacman -Qdtq |  pacman -Rs -
In arch Linux, we can upgrade the full system by only one command using the Pacman. Use the following command to update the system:
sudo pacman -Suy
Let’s understand the meaning, S tell the pacman to synchronize the local database with the main database. u tells the pacman to upgrade the packages and y update the local catch on the system. Basically, this command synchronizes the local pacman database with the main repository database and then updates the system.
Now let’s see how we can search the package into the database of pacman. To search query in the name and description  of the package in the database use the following command:
sudo pacman -Ss   <query1>  <query2>
To search into already installed packages on the system, use the following command:
sudo pacman -Qs query1>  <query2>
To search the query into the local database use the following command:
sudo pacman -F query1>  <query2>
When pacman downloads the packages it stores the packages into the /var/cache/pacman/pkg/ and while uninstalling the package pacman does not delete these files. Pacman uses these files to downgrade the package or install the package. But it can take a lot of space to store these packages. So to delete the stored packages, use the following command:
sudo pacman -Sc
To remove all stored packages and catch, use the following command:
sudp pacman -Scc
By using pacman we can install packages other than the main repository of Arch Linux. Use the following command to install the packages
For local:
sudo pacman -U path_to_file.pkg.tar.xz
For remote package:
sudo pacman -U http://www.example.com/repo/example.pkg.tar.xz
Sometimes installing the packages with pacman we face some errors. Following are the mainly occurred errors with pacman:
Conflicting file error: This error occurs due to some conflict packages present in the repository. To solve this error we can manually rename the file or force the overwrite function. We can use the following command to overwrite the function:
pacman -S --overwrite glob package
Invalid package: This error can occur due to the partial installation of the packages. We can solve this error by deleting .part files in /var/cache/pacman/pkg/.
Locking database: This error can occur when pacman is interrupted while updating the database. To solve this error, delete the file /var/lib/pacman/db.lock and update the database. Use the following command to delete the file:
rm /var/lib/pacman/db.lock
kk773572498
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Docker - COPY Instruction
scp command in Linux with Examples
chown command in Linux with Examples
SED command in Linux | Set 2
nohup Command in Linux with Examples
chmod command in Linux with examples
mv command in Linux with examples
Array Basics in Shell Scripting | Set 1
Introduction to Linux Operating System
Basic Operators in Shell Scripting