How to use the command pacman (with examples)
- Linux
- December 25, 2023
Pacman is the package manager utility for Arch Linux. It is used to install, upgrade, and manage software packages. This article provides various use cases of the pacman
command with examples.
Use case 1: Synchronize and update all packages
Code:
sudo pacman -Syu
Motivation: The -Syu
option is used to synchronize the package databases and update all installed packages to their latest versions. This is useful to keep the system up to date and secure.
Explanation:
sudo
: This command is run with administrative privileges.pacman
: The package manager utility.-Sy
: The-S
option is used for synchronizing the package databases, and the-y
option answers “yes” to all confirmation prompts without user intervention.-u
: The-u
option upgrades all packages that are out of date.
Example output:
:: Synchronizing package databases...
core 167.5 KiB 2022 KiB/s 00:00 [###################] 100%
extra 1972.1 KiB 7986 KiB/s 00:00 [###################] 100%
community 6.6 MiB 8.46 MiB/s 00:01 [###################] 100%
multilib 192.9 KiB 6.84 MiB/s 00:00 [###################] 100%
:: Starting full system upgrade...
...
...
:: Proceed with installation? [Y/n]
Use case 2: Install a new package
Code:
sudo pacman -S package
Motivation: The -S
option is used to install a new package from the package database. This is useful when you want to install software or libraries on your Arch Linux system.
Explanation:
sudo
: This command is run with administrative privileges.pacman
: The package manager utility.-S
: The-S
option is used to install packages from the package database.
Example output:
:: Synchronizing package databases...
core 167.5 KiB 2022 KiB/s 00:00 [###################] 100%
extra 1972.1 KiB 7986 KiB/s 00:00 [###################] 100%
community 6.6 MiB 8.46 MiB/s 00:01 [###################] 100%
multilib 192.9 KiB 6.84 MiB/s 00:00 [###################] 100%
:: Starting full system upgrade...
...
...
:: Proceed with installation? [Y/n]
Use case 3: Remove a package and its dependencies
Code:
sudo pacman -Rs package
Motivation: The -Rs
option is used to remove a package and its dependencies. This is useful when you want to uninstall software or libraries from your Arch Linux system.
Explanation:
sudo
: This command is run with administrative privileges.pacman
: The package manager utility.-Rs
: The-R
option is used to remove packages, and the-s
option is used to remove the package’s unused dependencies.
Example output:
checking dependencies...
:: a package and its dependencies will be removed
:: Do you want to remove package? [Y/n]
Use case 4: Search the database for packages containing a specific file
Code:
pacman -F "file_name"
Motivation: The -F
option is used to search the package database for packages containing a specific file. This is useful when you want to determine which package provides a particular file.
Explanation:
pacman
: The package manager utility.-F
: The-F
option is used to search for a specific file in the package database.
Example output:
core/package_name file_name
extra/package_name file_name
community/package_name file_name
Use case 5: List installed packages and versions
Code:
pacman -Q
Motivation: The -Q
option is used to list all installed packages and their versions. This is useful when you want to check which packages are currently installed on your system.
Explanation:
pacman
: The package manager utility.-Q
: The-Q
option is used to list all installed packages.
Example output:
package_name version_number
package_name version_number
...
Use case 6: List only the explicitly installed packages and versions
Code:
pacman -Qe
Motivation: The -Qe
option is used to list only the explicitly installed packages and their versions. This is useful when you want to differentiate between packages that were installed as dependencies and packages that were installed directly by the user.
Explanation:
pacman
: The package manager utility.-Qe
: The-Qe
option is used to list only explicitly installed packages.
Example output:
package_name version_number
package_name version_number
...
Use case 7: List orphan packages
Code:
pacman -Qtdq
Motivation: The -Qtdq
option is used to list orphan packages, which are installed as dependencies but not actually required by any package. This is useful when you want to remove unnecessary packages from your system.
Explanation:
pacman
: The package manager utility.-Qtdq
: The-Qtdq
option is used to list orphan packages.
Example output:
orphan_package_name
orphan_package_name
...
Use case 8: Empty the entire pacman cache
Code:
sudo pacman -Scc
Motivation: The -Scc
option is used to empty the entire pacman cache. This is useful when you want to free up disk space by removing all downloaded package files.
Explanation:
sudo
: This command is run with administrative privileges.pacman
: The package manager utility.-Scc
: The-Scc
option is used to empty the entire pacman cache.
Example output:
Cache directory: /var/cache/pacman/pkg/
:: Do you want to remove ALL files from cache? [y/N]
Conclusion:
The pacman
command is a powerful package manager utility for Arch Linux. It provides a wide range of functionalities, such as synchronizing and updating packages, installing and removing packages, searching for specific files in the package database, and managing dependencies. By understanding and utilizing the different use cases of the pacman
command, users can efficiently manage software packages on their Arch Linux systems.