Essential Pacman Commands for Arch Linux [With Examples]

5 min


The package manager pacman is a very handy utility. You can do a whole lot of things just using some simple commands. Here we take a look at some of the essentials pacman command examples for Arch Linux (and other derivatives such as Manjaro) for your daily use. Have a look.

The pacman is the official package manager for Arch Linux. It is being used by all the Arch Linux derivatives such as Manjaro. Using pacman you can do almost all types of package management operations such as install, uninstall, download, build, etc. Hence it is essential to know various pacman example commands for daily use.

In this guide, we give you the reference commands for pacman to perform various operations. Here’s the table of contents of this guide.

  1. Update system
  2. Upgrade system
  3. Upgrade a single package
  4. Search a package
  5. Search dependencies of a package
  6. Install a package
  7. Download a package locally
  8. Install a package from the local disk
  9. Install a package from a remote location
  10. Reinstall a package
  11. Uninstall a package
  12. Uninstall with dependencies
  13. Export the installed package list
  14. Complete list of installed packages
  15. Clean up your system

Pacman command examples for Arch

Most of the commands that are used require admin privilege. So, use sudo or run these commands using an ID having admin privileges.

Examples where is present in the syntax, replace them using the actual name of your package in question. Also, most of the pacman commands described below accept multiple package names delimited by spaces wherever applicable.

1. Updating your system

This command sync and download the fresh copy of the master package database from the server which is defined in pacman.conf file.

sudo pacman -Syy
-S: sync packages
-y: download fresh package database
y: the second y forces the download even if it is upto date
pacman -Syy
pacman -Syy

2. Upgrade system

pacman -Syu

This upgrades all packages that are out-of-date following the sync and download the fresh package database.

pacman -Syu
pacman -Syu

3. Upgrade a single package

If you want to update a single package use the package name at the end. For example, if you want to upgrade firefox only, leaving other packages in your system, use the below.

pacman -S firefox

4. Search package

The following command searches a package in name and its description in Arch repository (core, extra, and community).

pacman -Ss notepad++

This searches all substring of the parameter passed. You do not need to use wild cards. One thing though, depending on the search string the result can be a lot. So, you might want to filter the result out using grep or something else.

Search a package
Search a package

5. Search Package with all Dependencies

pacman -Si package

This command is ideal to list all the details about the package such as dependencies, package versions, etc. Basically all information about the package. Remember, you need the exact package name for this command to work. Wild card search doesn’t work in this command.

Search a package with dependencies - pacman command examples
Search a package with dependencies – pacman command examples

6. Install Package

Before you install any package, make sure to run pacman -Syu to make your system up to date.

If you know the package name, you can install it using the following command.

sudo pacman -S package

For example:

sudo pacman -S firefox

This command shows how much to be downloaded and what is the estimated disk space to be used after installation.

7. Download a package without installing

Not always you want to install a package. Sometimes you may want to just download the package for offline installation. Example:

sudo pacman -Sw smplayer

The downloaded file is kept at /var/cache/pacman/pkg defined in the /etc/pacman.conf file.

8. Install a locally downloaded package

You can install local packages using the following syntax.

sudo pacman -U /path/to/package

9. Install package directly from URL

If you want to install any package directly from remote network computers, servers, or mirrors, you can easily do that by providing the URL.

sudo pacman -U http://….

10. Re-install packages

You can re-install all packages installed in your system using the following command. Be cautious while running the below command, as it might be a huge list of packages and download may take time.

pacman -Qnq | pacman -S -

11. Unsintall a package

Uninstallation is simple. Run the below command to uninstall a package.

sudo pacman -R package

However, above command only uninstall the package, not its dependencies.

SEE ALSO:   How to Recover Arch Linux Install via chroot

12. Uninstall with dependencies that are not required by other apps

You can use different switches to uninstall a package using pacman including all of its dependencies.

For example:

sudo pacman -Rsun firefox
  • n: Ignore backups – that is, remove backups as well
  • s: recursively remove each target that is not required by any other packages or manually installed
  • u: Remove packages not required by any other packages.

You can use any combinations of the above switches for your need.

13. Show details about installed packages and dependencies

The following command shows the information of a package and its dependencies. The output contains the dependent packages, the list of packages on which this package is dependent upon and a list of optional dependencies.

pacman -Qi package

14. Complete list of installed packages

If you want a complete list of installed packages in your system, you may use the following command.

pacman -Q

You can redirect the output to a text file for further processing.

pacman -Q > complete_list.txt

You can also list explicitly installed packages that are not required by any other package, using the below command.

pacman -Qet

The above commands display the package name and versions delimited by space. You can only extract package names using the below:

pacman -Qe | awk '{print $1}'

15. Clean up system

You can use the following commands to perform several cleanup processes in your system.

The below command cleans the unused sync databases and packages no longer installed from the cache. So this removes all cache files that are no installed. Cache files are stored in /var/cache/pacman/pkg/.

First, you can check manually how much disk space is used by pacman cache files.

du -h /var/cache/pacman/pkg
Check disk space used by pacman cache
Check disk space used by pacman cache

Then you can run the following to clean.

sudo pacman -Sc
Clean pacman cache files
Clean pacman cache files

If you want to clear all cache file use the switch twice.

sudo pacman -Scc

The above commands can be super useful to free up disk space.

The pacman files

The followings are some of the important pacman files which are used by this package. You can analyze these for troubleshooting and configuration work.

  1. The main configuration file which contains pacman settings is –
/etc/pacman.conf
  • Cached file location
/var/cache/pacman/pkg/
  • Database file location
/var/lib/pacman/sync
  • Logfile location which contains all pacman command you ran till date and details. You can analyze this file for troubleshooting purposes.
/var/log/pacman.log

I hope these pacman command examples are useful for you for doing several pacman related tasks in the Arch system. The list of options of pacman is huge which you can read on man pages. However, this is a summary of essential pacman commands filtered out for reference.

What is that pacman command which you think should be included here? Let me know in the comments.


We bring the latest tech, software news and stuff that matters. Stay in touch via Telegram, Twitter, YouTube, and Facebook and never miss an update!

Join our Telegram channel and stay informed on the move.

Also Read


Like it? Share with your friends!

Arindam

Creator of debugpoint.com. All time Linux user and open-source supporter. Connect with me via Telegram, Twitter, or send us an email.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

4 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
4
0
Would love your thoughts, please comment.x
()
x