Operating on Packages

Learn how to install, remove and update packages.

We'll cover the following

Each Unix environment provides a special program for accessing the repository. It is called a package manager.

Why does the Unix environment need a package manager when Windows does not have such a program? Users of this OS download all software from the internet and install it manually.

There are several third-party package managers for Windows. The most popular one is Chocolatey. Microsoft plans to develop the official package manager in the nearest future.

The package manager installs and removes packages on the Unix environment. Its main task is to keep track of package dependencies.

We can see how useful this is with an example. Let’s suppose that some program from one package uses features of the library from another package. Then, the first package depends on the second one. This means that we should install the second package whenever we install the first one.

Package dependency allows us to have a single copy of every program and library in our file system. All dependent programs know the installation path of the software they need. This way, they can share it.

We should install all software on our Unix environment or Linux system using the package manager, with one exception. If we need a proprietary program, we have to install it manually. Usually, such a program is distributed in a single package. It includes all dependencies, which are necessary programs and applications. There is no need to track dependencies in this case. Therefore, we can install the program without the package manager.

Here is the algorithm to install a package from the repository:

  1. Download a package index from the repository.

  2. Find the required program or library in the package index.

  3. Download the package with the program or library from the repository.

  4. Install the downloaded package.

The package manager does all these steps. It has parameters and options that choose an action to do. We need to know them for installing packages properly.

Package manager pacman

The MSYS2 environment uses the package manager called pacman. It was developed for the Arch Linux distribution. The pacman manager operates packages of the ZST format. We do not need any extra knowledge about this format now.

Let’s take the pacman manager as an example and consider the commands for accessing the repository.

The following command downloads the package index of the repository:

pacman -Syy

When we get the package index on our computer, we can find the required package there. This command finds it by the KEYWORD:

pacman -Ss KEYWORD

Let’s suppose that we look for a utility to process MS Word documents. The following command finds the right package for that:

pacman -Ss word

This command gives you two options:

  • mingw-w64-i686-antiword
  • mingw-w64-x86_64-antiword

These are builds of the antiword utility for 32-bit and 64-bit systems. The utility converts MS Word documents to text format.

Now, we can run the following command that installs the PACKAGE:

pacman -S PACKAGE

This command installs the package with the antiword utility:

pacman -S mingw-w64-x86_64-antiword

When this command finishes, we get the antiword utility and all packages that it needs for running.

Now, we can launch the antiword utility for the my_report.doc file this way:

antiword my_report.doc

This command prints the document contents in text format.

We installed the new package on our system. If it becomes unnecessary, we can uninstall it. When we do it, the package manager uninstalls both the package and all its dependencies. However, this only happens when there are no other programs that require them.

Here is the command to uninstall some PACKAGE:

pacman -Rs PACKAGE

The following command uninstalls the package of the antiword utility:

pacman -Rs mingw-w64-x86_64-antiword

Let’s suppose that we installed several new packages on our system. After a while, maintainers compile new versions of these packages and push them to the repository. We want to get these new versions because of their features. The following command does that:

pacman -Syu

This command updates all installed packages on our system to their actual versions in the repository.

We considered the basic pacman commands. Other package managers work the same way. They follow the same algorithm as pacman when installing and removing packages. However, they have other command-line parameters.

The following table shows how to use package managers of several well-known Linux distributions.

Command MSYS2 and Arch Linux Ubuntu CentOS Fedora
Download a package index. pacman -Syy apt-get update yum check-update dnf check-update
Search for a package by some keyword. pacman -Ss KEYWORD apt-cache search KEYWORD yum search KEYWORD dnf search KEYWORD
Install the package from the repository. pacman -S PACKAGE_NAME apt-get install PACKAGE_NAME yum install PACKAGE_NAME dnf install PACKAGE_NAME
Install the package from the local file. pacman -U FILENAME dpkg -i FILENAME yum install FILENAME dnf install FILENAME
Remove the installed package. pacman -Rs PACKAGE_NAME apt-get remove PACKAGE_NAME yum remove PACKAGE_NAME dnf erase PACKAGE_NAME
Update all installed packages. pacman -Syu apt-get upgrade yum update dnf upgrade

Get hands-on with 1400+ tech skills courses.