Using Pacman on Arch and Manjaro

When trying out a new Linux distribution, one of the first things you need to familiarize yourself with is the system’s package manager. Arch Linux and other Arch-based distros, like Manjaro, use pacman to install or update packages, remove software, and keep the system up to date. Pacman isn’t related to the classic video game, rather just an acronym of package manager.

In this guide, you’ll learn how to use pacman on Arch Linux, Manjaro, and other distros based on Arch. It works the same across any of them. Read on to master pacman with commands to install packages, remove packages, update the system, etc.

Install a Package

The -S (Synchronize) option is used to install a new package. Note that this is an uppercase S, not lowercase.

$ sudo pacman -S vim

This is enough by itself, but it’s usually a good idea to also include the -y and -u options.

$ sudo pacman -Syu vim
  • -S – Synchronize your system packages with those in the remote repository
  • -y – Download latest package information from remote server
  • -u – Upgrade all installed packages to latest version

Installing a new package with pacman

By specifying all three options, it ensures that our system is completely up to date, we have the latest package information, and we also install the new packages that we have entered in the command. If you’re not interested in upgrading the entire system (for example, if you’re in a hurry), then simply use the -Sy options. Omitting the -y means you might not obtain the latest version of the package you’re trying to install.

$ sudo pacman -Sy vim

Pacman will show you a quick summary of what package is going to be installed, as well as any dependencies. You just need to answer y (yes) to this prompt to continue with the installaion.

resolving dependencies...
looking for conflicting packages...

Packages (2) vim-runtime-8.2.2891-1  vim-8.2.2891-1

Total Download Size:    8.24 MiB
Total Installed Size:  34.19 MiB

:: Proceed with installation? [Y/n] y

Reinstall a Package

If you already have a package installed, you can reinstall it with the same pacman -S command. Again, you should also include the -y option to make sure you install the latest version. If pacman finds that the package is out of date, it will be upgraded.

$ sudo pacman -Sy vim

warning: vim-8.2.2891-1 is up to date -- reinstalling
resolving dependencies...
looking for conflicting packages...

Packages (1) vim-8.2.2891-1

Total Installed Size:  3.87 MiB
Net Upgrade Size:      0.00 MiB

:: Proceed with installation? [Y/n]

Remove a Package

The -R (Remove) option is used to remove an installed package from the system. For example, this command will remove the vim package we installed in the previous section.

$ sudo pacman -R vim

Once again, pacman will give us a quick summary of the changes it’s about to make. Simply answer y to proceed.

Packages (1) vim-8.2.2814-1

Total Removed Size:  3.87 MiB

:: Do you want to remove these packages? [Y/n]

Normally, you will also want to include the -s (lowercase s) option, which tells pacman to remove dependencies that are no longer needed.

$ sudo pacman -Rs vim

Packages (2) vim-runtime-8.2.2891-1  vim-8.2.2891-1

Total Removed Size:  34.20 MiB

:: Do you want to remove these packages? [Y/n]

Do you notice the difference between this output and the previous output? Now pacman wants to remove two packages: vim and its dependency, which is a runtime package. Instead of removing 3 MB from our system, we are now removing 34 MB. Don’t worry, pacman has determined that this runtime dependency is no longer necessary, which is why it’s being removed along with the package we specified.

Downgrade a Package

If you find it necessary to roll back a package, you can find old versions inside the pacman cache directory at /var/cache/pacman/pkg/. Navigate to this directory and you will see the old and current versions of packages installed on your system.

Displaying packages in the pacman cache

Once you’ve identified the old package you wish to install, use the -U option with pacman and specify the file name of the old package.

$ sudo pacman -U /var/cache/pacman/pkg/vim-8.2.2891-1-x86_64.pkg.tar.zst

Remove Unnecessary Dependencies

If you have lingering dependencies on your system that are no longer required by any installed package, you can view them with the following command.

$ pacman -Qdtq
vim-runtime

In our case, we only have the vim-runtime lingering package, which was mentioned earlier. We could remove this package with a typical pacman -R command. Better yet, we can use the following command to remove all of the unnecessary dependencies from our system.

$ pacman -Qdtq | sudo pacman -Rs -

Removing unused package dependencies in pacman

Upgrade All Packages / Entire System

Since Arch Linux, Manjaro, and other distros based on Arch are rolling releases, upgrading the system is as simple as upgrading all of the currently installed packages. The following command will upgrade your system to the latest release.

$ sudo pacman -Syu

Performing full system upgrade with pacman package manager

Search for a Package

Each package in the official repositories has a name and description. You can search this data for keywords when you’re looking for a particular package to install. Use the -Ss options followed by the search term. For example, let’s search the repos for the OpenSSH package.

$ pacman -Ss openssh

core/openssh 8.6p1-1 [installed]
    Premier connectivity tool for remote login with the SSH protocol
community/lxqt-openssh-askpass 0.17.0-1 (lxqt)
    LXQt openssh password prompt
community/openssh-askpass 2.1.0-3
    A plasma-like passphrase dialog for ssh
community/perl-net-openssh 0.80-2
    Perl SSH client package implemented on top of OpenSSH
community/python-sshpubkeys 3.3.1-1
    OpenSSH public key parser for Python
community/tinyssh-convert 0.2-6
    Convert Ed25519 keys from OpenSSH to TinySSH format

As you can see from the output, OpenSSH is already installed on the system. Pacman also returns a list of packages that contain the “openssh” keyword we searched for. Any of these packages can be easily installed with the pacman -S command we covered earlier.

To search only for packages that are already installed on your system, you would use the -Qs options.

$ pacman -Qs ssh

local/lib32-libssh2 1.9.0-1
    A library implementing the SSH2 protocol as defined by Internet Drafts (32-bit)
local/libssh 0.9.5-1
    Library for accessing ssh client services through C libraries
local/libssh2 1.9.0-3
    A library implementing the SSH2 protocol as defined by Internet Drafts
local/openssh 8.6p1-1
    Premier connectivity tool for remote login with the SSH protocol

Clean Package Cache

When installing or upgrading packages with pacman, the software is downloaded to your system’s /var/cache/pacman/pkg/ directory. After some time, this directory can grow in size and chew up a lot of disk space. Although this sounds like a bad thing, it’s actually a nice feature because it allows packages to be easily downgraded or reinstalled without needing to download anything from package servers.

Even so, you should occasionally clear the package cache on your system with the pacman -Scc command. This will clear all downloaded software from your cache folder, and will also remove unused sync repositories.

$ sudo pacman -Scc

Cache directory: /var/cache/pacman/pkg/
:: Do you want to remove ALL files from cache? [y/N] y
removing all files from cache...

Database directory: /var/lib/pacman/
:: Do you want to remove unused repositories? [Y/n] y
removing unused sync repositories...

Install a Downloaded Package

You don’t always have to connect to official package reposities to install new software. If you download a package from an online site (and you are sure that you trust the source), you can use the -U option and specify the path to the file you wish to install.

$ sudo pacman -U vim-8.2.2891-1-x86_64.pkg.tar.zst

It’s also possible to install the package by pointing pacman to the URL where the package is hosted.

$ sudo pacman -U http://example.com/vim-8.2.2891-1-x86_64.pkg.tar.zst

Conclusion

This guide has served as an introduction to all of the most common commands to use with the pacman package manager on Arch Linux, Manjaro, and distros in the same family. Pacman is one of the most powerful and speedy package managers available, so you’ll learn to love it once you get the common options mastered.

If our content helped you, please consider buying us a coffee. We appreciate your support!

Buy me a coffee donation button

Leave a Comment

Your email address will not be published. Required fields are marked *