pacman
pacman
is a package manager, associated with Arch Linux and Arch-based distributions (like Manjaro). It allows for easy installation and management of packages.
Usage
pacman
has various capital letter flags that determine the action that will be performed:
Flag | Description |
---|---|
-S , --sync |
Synchronize package(s) with the server. |
-U , --upgrade |
Upgrade packages from a given source. |
-R , --remove |
Remove package(s) from the system. |
-Q , --query |
View information about installed package(s). |
There are some other action that can be performed, but they are not as useful as the ones above. Consult the manpage or the sources of this article if you wish to know more.
Install/upgrade packages
To install/upgrade packages, use the -S
flag. Here are some possible syntaxes:
sudo pacman -S vlc # install package
sudo pacman -S community/audacity # install package from repository
sudo pacman -S xorg-{xprop,xrandr} # install two similar packages
Alternatively, if you wish to install packages not found in the package database, use:
sudo pacman -U <file/url>
Removing packages
Removing packages is very similar to installing them – all you have to do is use the -R
flag:
sudo pacman -R <package>
You might also wish to use some additional flags to remove other packages too (but be careful, especially with -c
– they’re recursive):
-s , --recursive |
Also remove dependencies not required by other packages. |
-c , --cascade |
Also remove packages that depend on this package. |
Upgrading the system
To upgrade the system (i. e. all of the packages), use sudo pacman -Syu
, where:
-y
upgrades the package database from the server-u
upgrades the packages themselves
You might also want to ignore upgrading some packages, if you’re not yet ready for the upgrade (if, for example, you’re currently using them and don’t want them to break):
--ignore <p1,p2,p3> |
Don’t upgrade the specified packages. |
--ignoregroup <p1,p2,p3> |
Don’t upgrade the specified package groups. |
Querying packages
For querying, many various results can be achieved. The general syntax is:
pacman -Q <package(s)>
Keep in mind that the flags are very important here, since there are a lot of possible things you might want to query. Here is a brief rundown:
-e , --explicit |
Only list explicitly installed packages.1 |
-i , --info |
List information about the package. |
-l , --list |
List files owned by this package. |
-o <f> , --owns <f> |
List, which package owns the specified file. |
-m , --foreign |
List packages not found in the sync database.2 |
-n , --natived |
Opposite of -m . |
-s <r> , --search <r> |
List packages, whose names/descriptions matches a regex. |
-u , --upgrades |
List out-of-date packages. Good to prepend with -y . |
Feel free to chain these flags (mostly) however you wish to, to get the information you desire.
Tips & Tricks
Adding color
pacman
offers colorful output out-of-the-box – all you have to do to enable it (since it’s disabled by default) is to uncomment Color
in /etc/pacman.conf
.
Internals
pacman
is written in C, because C kind of looks like a Pacman 😎.
The packages themselves are stored in tar archives, mainly containing the following:
- compiled application files
- package metadata (name, version…)
- directives (how to install)
The fact that pacman
doesn’t compile the packages but instead installs binaries is quite important, since this makes it much faster and easier. Although this means that you don’t have the source code at hand, you can use asp
to retrieve source files for pacman
packages.
The log files are stored in /var/log/pacman.log
, in case you need to undo some bad decision (adding/removing packages that you shouldn’t have, for example). This saved me on multiple occasions, when I didn’t pay enough attention to what Pacman was saying and rebooted the system, only to find everything completely broken.
Useful commands
Clear cache
sudo pacman -Sc
Sources
man pacman
- Arch Linux wiki:
- StackOverflow:
-
For some reason, I had quite a difficulty understanding what “explicitly” actually means here. For clarification: packages are explicit, when they are installed by the user using a command, or when installed with the
--asexplicit
flag. ↩ -
This can happen either when installing packages using
-U
, or through programs likeyay
,yaourt
,… that use AUR to get the packages from. ↩