Arch Linux

How to Update the Pacman Databases on Arch Linux

Every Linux distribution has a package repository where precompiled packages are kept. Of course you can download and install these packages manually, but that is sometimes time consuming or nearly impossible. Because each Linux packages has some dependencies, that is they depend on some other packages, which in order depends on some other ones and so on. So a tool called package manager was created to automatically download and install packages along with their dependencies.

The package manager keeps a local database of all the packages available in the package repository. In that database information like where the packages can be downloaded, their download size, their dependency packages and so on are kept. So it is very important that we keep it up to date.

The name of the package manager tool for Arch Linux is Pacman. If the Arch Linux package manager database is not up to date, old version of packages may be installed. Sometimes Pacman will fail to install any packages due to some sort of dependency problem.

One of the major problem I’ve faced when my Pacman database was out of date and I tried to install a certain package was Pacman fail to find the package on the server!

You know Arch Linux is a rolling released distro, that is, existing packages in the Arch Linux repositories are updated as soon as they are released. So it is mandatory we keep the Pacman database up to date.

In this article, I will show you how to update the Pacman database on Arch Linux. Let’s get started.

Updating the Pacman Database

You can update the Pacman database cache with the following command:

$ sudo pacman -Syy

The Pacman package cache should be updated as you can see from the screenshot below.

Changing the Pacman Mirrors

There are many Arch Linux mirrors all around the world. You can choose a specific mirror depending on your geographical region. Choosing your nearest Arch Linux mirror may speed up your package download speed, which of course saves your valuable time.

The Pacman mirror configuration is in /etc/pacman.d/mirrorlist file. To change the mirror, you have to edit this file.

Run the following command to edit /etc/pacman.d/mirrorlist file:

$ sudo nano /etc/pacman.d/mirrorlist

Type in your password and press <Enter>.

You should see the following window. Here you have a list of all the Arch Linux mirrors.

All the mirrors are active by default. Here’s how Pacman selects a mirror. Pacman tries the first mirror (the first line starting with Server = xxx) in the list, if it can’t connect to it due to network error, or if the server is unavailable, it tries the next mirror (the second line starting with Server = xxx) on the list.

In my case, as you can see in the green marked section of the screenshot below, Pacman tries the first mirror Bangladesh, then if it succeeds, it no longer needs to check what’s next. If it fails to connect to it, it tries the second mirror, which is United States as marked red in the screenshot below.

NOTE: Lines starting with double hash (##) are comments. They have no meaning. They are only for documentation purpose.

If you want to change the mirror, scroll down the list and choose a mirror. Then press <Ctrl> + k to cut the mirror line.

Then scroll up and paste the mirror line before any other mirror line by pressing <Ctrl> + u.

Now to save the file, press <Ctrl> + x and then press y and then press <Enter>.

Now update the Pacman package repository cache with the following command:

$ sudo pacman -Syy

Adding your Own Arch Linux Mirror

Your ISP may host their own Arch Linux mirror to speed up the download of Arch Linux packages. It may not be listed on your /etc/pacman.d/mirrorlist. If that’s the case, you can add it to your /etc/pacman.d/mirrorlist file manually.

Just edit the /etc/pacman.d/mirrorlist with the following command:

$ sudo nano /etc/pacman.d/mirrorlist

Now add the following line to the beginning of the file.

Server = http://your/arch/linux/mirror/server

Now save the file by pressing <Ctrl> + x. Then press y and then press <Enter>. Then update your Pacman package repository cache again with sudo pacman -Sy

That’s how you update the Pacman database on Arch Linux. Thanks for reading this article.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.