{"id":2586,"date":"2023-03-24T01:45:12","date_gmt":"2023-03-23T20:15:12","guid":{"rendered":"https:\/\/smarttech101.com\/?p=2586"},"modified":"2023-03-25T00:45:39","modified_gmt":"2023-03-24T19:15:39","slug":"how-to-use-pacman-in-arch-linux","status":"publish","type":"post","link":"https:\/\/smarttech101.com\/how-to-use-pacman-in-arch-linux\/","title":{"rendered":"How to Use Pacman in Arch Linux"},"content":{"rendered":"\n
The pacman is a package manager for Arch Linux-based distros (ex – Arch Linux, Manjaro, ArcoLinux, Artix Linux, Garuda Linux, ArcoLinux, Archlabs Linux, etc.). It installs, removes, updates, and everything else related to your packages. It is a very powerful package manager. AUR helpers like In this article, I will talk about pacman’s configuration, how to use it to install and remove any package, how to update\/downgrade a package, upgrade your Arch Linux-based distros. Finally, I will give you a very useful and simple script that will handle all such operations<\/strong>.<\/p>\n\n\n\n We use the file Currently, I use the following configuration in it:<\/p>\n\n\n\n Many of the above options were already uncommented. I have uncommented the following options:<\/p>\n\n\n\n Other options might be important to you:<\/p>\n\n\n\n As you can see in pacman configuration file Arch User Repository (AUR)<\/a> on the other hand is not the official repository (repo). Anyone can upload his\/her packages in the AUR. Packages in the AUR are not checked as rigorously as those in the official repository for malware, system breakage, and other problems. Despite these drawbacks, it is very important since packages from the AUR are chosen very often to get into the official repositories. On top of that, many famous packages like Google Chrome are only available in this. So, use this repository only if you trust the package.<\/p>\n\n\n\n So, whenever you install any app, try your best to stick with the packages from these repositories. When you upgrade your system, these apps along with their dependencies will also be updated with the upgrade command So, overall preference of repositories:<\/p>\n\n\n\n core > extra > community > AUR > GitHub and others<\/strong><\/p>\n\n\n\n To install a package Example:<\/p>\n\n\n\n Use the flag Pacman keeps a list of all packages and related information (like version, dependency, etc.) in a special database. You need to periodically update this database.<\/p>\n\n\n\n For this execute the following command<\/p>\n\n\n\n or<\/p>\n\n\n\n You can create a cronjob<\/a> for this. Open the file You can create an anacron job if your computer is off very often. Use the file To upgrade your system use the Or,<\/p>\n\n\n\n It will update all the packages and their dependencies.<\/p>\n\n\n\n However, using The To get all information about any installed packages use the Example:<\/p>\n\n\n\n Note 1: <\/strong>Similar flag is also available with Note 2<\/strong>: The result in To find explicitly installed packages, use the flag Output:<\/p>\n\n\n\n \ud83d\ude01 Fun fact<\/strong>: It is helpful when you want to reinstall your Linux system. Just reinstall Arch Linux, and then reinstall the explicitly installed packages<\/strong>. Copy their configuration and you are done. Recall the amount of time you put into Windows for such an operation.<\/p>\n\n\n\n Extra point<\/strong>: To find the explicitly installed groups, execute the yay<\/code> also use pacman for installation and other related operations.<\/p>\n\n\n\n
Table of Contents<\/h2>\n\n\n\n
\n
\n
\n
\n
\n
\n
Configuration of pacman<\/h2>\n\n\n\n
\/etc\/pacman.conf<\/code> to configure the pacman. All the settings are mentioned in the file with their full description. Open it using your favorite text editor such as
nvim<\/code> and uncomment the options you want.<\/p>\n\n\n\n
$ sudo nvim \/etc\/pacman.conf<\/code><\/pre>\n\n\n\n
# See the pacman.conf(5) manpage for option and repository directives\n\n#\n# GENERAL OPTIONS\n#\n[options]\n# The following paths are commented out with their default values listed.\n# If you wish to use different paths, uncomment and update the paths.\n#RootDir = \/\n#DBPath = \/var\/lib\/pacman\/\n#CacheDir = \/var\/cache\/pacman\/pkg\/\n#GPGDir = \/etc\/pacman.d\/gnupg\/\n#HookDir = \/etc\/pacman.d\/hooks\/\nHoldPkg = pacman glibc\n#XferCommand = \/usr\/bin\/curl -L -C - -f -o %o %u\n#XferCommand = \/usr\/bin\/wget --passive-ftp -c -O %o %u\n#CleanMethod = KeepInstalled\nArchitecture = auto\n\n# Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup\n#IgnorePkg =\n#IgnoreGroup =\n\n#NoUpgrade =\n#NoExtract =\n\n# Misc options\n#UseSyslog\nColor\n#NoProgressBar\nCheckSpace\nVerbosePkgLists\nParallelDownloads = 5\n\n# By default, pacman accepts packages signed by keys that its local keyring\n# trusts (see pacman-key and its man page), as well as unsigned packages.\nSigLevel = Required DatabaseOptional\nLocalFileSigLevel = Optional\n#RemoteFileSigLevel = Required\n\n# NOTE: You must run `pacman-key --init` before first using pacman; the local\n# keyring can then be populated with the keys of all official Arch Linux\n# packagers with `pacman-key --populate archlinux`.\n\n#\n# REPOSITORIES\n# - can be defined here or included from another file\n# - pacman will search repositories in the order defined here\n# - local\/custom mirrors can be added here or in separate files\n# - repositories listed first will take precedence when packages\n# have identical names, regardless of version number\n# - URLs will have $repo replaced by the name of the current repo\n# - URLs will have $arch replaced by the name of the architecture\n#\n# Repository entries are of the format:\n# [repo-name]\n# Server = ServerName\n# Include = IncludePath\n#\n# The header [repo-name] is crucial - it must be present and\n# uncommented to enable the repo.\n#\n\n# The testing repositories are disabled by default. To enable, uncomment the\n# repo name header and Include lines. You can add preferred servers immediately\n# after the header, and they will be used before the default mirrors.\n\n#[testing]\n#Include = \/etc\/pacman.d\/mirrorlist\n\n[core]\nInclude = \/etc\/pacman.d\/mirrorlist\n\n[extra]\nInclude = \/etc\/pacman.d\/mirrorlist\n\n#[community-testing]\n#Include = \/etc\/pacman.d\/mirrorlist\n\n[community]\nInclude = \/etc\/pacman.d\/mirrorlist\n\n# If you want to run 32 bit applications on your x86_64 system,\n# enable the multilib repositories as required here.\n\n#[multilib-testing]\n#Include = \/etc\/pacman.d\/mirrorlist\n\n[multilib]\nInclude = \/etc\/pacman.d\/mirrorlist\n\n# An example of a custom package repository. See the pacman manpage for\n# tips on creating your own repositories.\n#[custom]\n#SigLevel = Optional TrustAll\n#Server = file:\/\/\/home\/custompkgs<\/code><\/pre>\n\n\n\n
\n
Color<\/code>: gives colored output<\/li>\n<\/ul>\n\n\n\n
\n
VerbosePkgLists<\/code>: makes a good-looking table with
-><\/code> to showcase changes. See the above image.<\/li>\n\n\n\n
ParallelDownloads = 5<\/code>: by default, pacman downloads only one package during installation\/upgrade\/update. Using this option forces pacman to download 5 packages at a time. Thus it increases the download speed.<\/li>\n<\/ul>\n\n\n\n
\n
IgnorePkg = package1 package2<\/code>: Now, these packages
package1<\/code> and
package2<\/code> will be ignored by pacman. That means pacman will not update them with the system upgrade command
Pacman -Syu<\/code>. Put a list of all the packages you don’t want to update. And do not forget the spaces in between them. This is helpful when updating some package is breaking it. This might be the case with bleeding-edge distros like Arch Linux which updates very often. However, in my whole life, I never needed to use this \ud83d\ude01.<\/li>\n<\/ul>\n\n\n\n
Repositories in Arch Linux<\/h2>\n\n\n\n
\/etc\/pacman.conf<\/code>, there are four official repositories<\/p>\n\n\n\n
\n
core<\/code>: fundamental Linux packages like
curl<\/code>,
bash<\/code>, etc. are found here.<\/li>\n\n\n\n
extra<\/code>: Most mainstream GUI packages like
firefox<\/code>,
gnome-desktop<\/code>, etc. can be found here.<\/li>\n\n\n\n
community<\/code>: the biggest official repository. If you are a developer and want your package to get included in the official Arch Linux repository, it is highly likely your package will end up here. Example –
ranger<\/code>,
i3-gaps<\/code><\/li>\n\n\n\n
multilib<\/code>: 32-bit packages can be found here. Gamers find it very useful since packages like Wine, and Steam, are located here.<\/li>\n<\/ul>\n\n\n\n
pacman -Syu<\/code>. This will cause fewer problems in your system and packages. And if you cannot find your package in the official repository, then prefer AUR to GitHub and other sources because AUR installs all the dependencies, and uninstallation of packages is very easy – just use the pacman.<\/p>\n\n\n\n
How to install packages using pacman in Arch Linux<\/h2>\n\n\n\n
myapp<\/code> use the following command:<\/p>\n\n\n\n
$ sudo pacman -S myapp<\/code><\/pre>\n\n\n\n
$ sudo pacman -S firefox<\/code><\/pre>\n\n\n\n
--noconfirm<\/code> if you don’t want to write
y<\/code> each time you install something. Similarly, use
--needed<\/code> to install only the needed packages i.e. do not install the packages which are already installed and updated.<\/p>\n\n\n\n
$ sudo pacman -S firefox --noconfirm --needed<\/code><\/pre>\n\n\n\n
How to upgrade pacman database<\/h3>\n\n\n\n
$ sudo pacman -Sy<\/code><\/pre>\n\n\n\n
$ sudo pacman -S -y<\/code><\/pre>\n\n\n\n
\/etc\/crontab<\/code> using your text editor and add the following line. Change the time and\/or day according to your need.<\/p>\n\n\n\n
$ sudo nvim \/etc\/crontab\n\n# pacman's local database update at 06:48 daily\n48 6 * * * root pacman -Sy<\/code><\/pre>\n\n\n\n
\/etc\/anacrontab<\/code>. To learn more about how to create an anacron job<\/a>, read my article on it.<\/p>\n\n\n\n
$ sudo nvim \/etc\/anacrontab\n\n# pacman's local database update at every 1st day\n1 0 pacman_database pacman -Sy <\/code><\/pre>\n\n\n\n
How to upgrade Arch Linux<\/h3>\n\n\n\n
pacman -Su<\/code> command.<\/p>\n\n\n\n
$ sudo pacman -Su<\/code><\/pre>\n\n\n\n
$ sudo pacman -S -u<\/code><\/pre>\n\n\n\n
-Syu<\/code> (aka
-S -y -u<\/code>) will be better since that will update the database as well. Now, you will get the latest packages.<\/p>\n\n\n\n
$ sudo pacman -Syu<\/code><\/pre>\n\n\n\n
How to use pacman to learn about installed packages in Arch Linux<\/h2>\n\n\n\n
-Q<\/code> operation in the pacman and all its associated flags give you information about the local packages. Using this, you can find files, and dependencies brought by the package, whether the package has been installed as a dependency or explicitly by you, whether the package is part of a group, and so on.<\/p>\n\n\n\n
How to get all information about installed packages<\/h3>\n\n\n\n
-Qi<\/code>:<\/p>\n\n\n\n
$ pacman -Qi package_name<\/code><\/pre>\n\n\n\n
$ pacman -Qi dconf\nName : dconf\nVersion : 0.38.0-1\nDescription : Configuration database system\nArchitecture : x86_64\nURL : https:\/\/wiki.gnome.org\/Projects\/dconf\nLicenses : LGPL\nGroups : None\nProvides : libdconf.so=1-64\nDepends On : glib2\nOptional Deps : None\nRequired By : colord gsettings-desktop-schemas gtk3 gvfs\nOptional For : None\nConflicts With : None\nReplaces : None\nInstalled Size : 443.25 KiB\nPackager : Jan Alexander Steffens (heftig) <heftig@archlinux.org>\nBuild Date : Thu 17 Sep 2020 11:58:07 PM IST\nInstall Date : Mon 23 Nov 2020 08:31:39 PM IST\nInstall Reason : Installed as a dependency for another package\nInstall Script : Yes\nValidated By : Signature<\/code><\/pre>\n\n\n\n
-S<\/code>.
-Qi<\/code> is all about ‘your’ system<\/p>\n\n\n\n
$ pacman -Si dconf\n\nRepository : extra\nName : dconf\nVersion : 0.40.0-2\nDescription : Configuration database system\nArchitecture : x86_64\nURL : https:\/\/wiki.gnome.org\/Projects\/dconf\nLicenses : LGPL\nGroups : None\nProvides : libdconf.so=1-64\nDepends On : glib2\nOptional Deps : None\nConflicts With : None\nReplaces : None\nDownload Size : 105.75 KiB\nInstalled Size : 457.01 KiB\nPackager : Jan Alexander Steffens (heftig) <heftig@archlinux.org>\nBuild Date : Thu 17 Nov 2022 11:08:58 PM IST\nValidated By : MD5 Sum SHA-256 Sum Signature<\/code><\/pre>\n\n\n\n
pacman -Qi package_name<\/code> is a little different from that in
pacman -Si package_name<\/code>. For example, look at the line starting with
Required by<\/code>. This line tells which packages are using it as a dependency in ‘your’ system.<\/p>\n\n\n\n
How to find explicitly installed packages in Arch Linux<\/h3>\n\n\n\n
-Qe<\/code>.<\/p>\n\n\n\n
$ pacman -Qe<\/code><\/pre>\n\n\n\n
accountsservice 22.08.8-4\nalsa-utils 1.2.8-1\namd-ucode 20230210.bf4115c-1\nani-cli-git r662.ec28d2a-1\nanki 2.1.60-1\natool 0.39.0-8\nautoconf 2.71-4\nautomake 1.16.5-2\n...<\/code><\/pre>\n\n\n\n
-Qge<\/code> (
g<\/code> for group,
e<\/code> for explicit):<\/p>\n\n\n\n
$ pacman -Qge<\/code><\/pre>\n\n\n\n
Search for installed packages using regular expression in Arch Linux<\/h3>\n\n\n\n