Latest Stories

Featured Stories

Filter By Categories
Ramesh Vishveshwar
By
November 16, 2018

Linux Package Managers

Installing software on the desktop seems relatively easy, especially if you are more used to the Windows environment. Download & extract the software, find the .msi/,exe file, double click it and wait as the progress bar reaches 100%. On the Linux server, it is sometimes not as easy as that. Let’s say you want to install a CMS on your VPS and begin blogging, you will need to install a web server, the corresponding DB package and so on.

In a world without package managers, if you had to install nginx, you would manually have to install a number of packages first, such as OpenSSL, zlib and PCRE. Package managers bring in the following benefits

  • A common location to manage all libraries and packages right from the kernel, operating system to various applications
  • Package managers connect to official repositories to download and install, this means that you can rely on what is being installed.
  • Dependency resolution is handled using metadata in the package you are installing. Going back to the nginx example, the package metadata contains the dependencies and if not already present on the server, will be downloaded and installed. This way packages can be slimmer and not contain every dependency.
  • Many applications have fixed locations for configuration files. Running the application means that the binary looks for certain files in certain fixed locations. Installing via a package manager, means that the installation is controlled and install paths are fixed and known.
  • Each flavor of Linux has a standard binary package format (.deb for Ubuntu/Debian and .rpm for Centos/RHEL). This eases installation across systems, so you can’t accidentally install something not meant for the current Linux flavor.

You may already have used yum/apt-get which are the package managers for CentOS and Ubuntu/Debian systems respectively. Let’s dive in with the various options with these package managers

Yellow Dog Updater, Modified (YUM)

CentOS, RHEL and older version of Fedora (until v22), use YUM to interact with repositories and install packages. yum also contains a tool called rpm which is used to install individual packages.

Installing new packages is as simple as

# yum install {package-name}

Adding a flag -y, installs the package without asking a confirmation

If you have downloaded a .rpm file which is not present in any known repository, you can perform a localinstall

# yum localinstall /path/to/file-name.rpm

Removing packages uses either the erase or remove option

# yum erase {package-name}

Or

# yum remove {package-name}

Any dependencies that were installed for {package-name} and are no longer needed, can be removed when you execute yum with the autoremove option

# yum autoremove

Sometimes package names have an included version number and you may not know the complete package name, in such cases, yum search followed by the package name helps in listing the exact package name.

To update all packages, run

# yum update

Adding Custom Repositories

By installing a tool called yum-utils, you can add custom repositories using the --add-repo option

# yum install yum-utils

The above installs yum-utils, following which you can add a new repo URL

# yum-config-manager --add-repo {url-of-repo}

If you are not too keen on installing yum-utils, you can also manually add a repository as a .repo file in /etc/yum.repos.d/

To add a repo for google search create a file /etc/yum.repos.d/google.repo and add the following

[google]

name=Google - $basearch

baseurl=http://dl.google.com/linux/rpm/stable/$basearch

enabled=1

gpgcheck=1

gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub

You are now ready to install packages from Google’s repo

From yum version > 3.2.x, a history option was added which provided admins with detailed history of what yum transactions were made on a system. This also allowed for admins to perform undos/redos or even rollback changes made.

Advanced Packaging Tool (APT)

Ubuntu & Debian users are familiar with apt-get to install packages. Here are the different options with apt-get

To install a package

# apt-get install {package-name}

If you want to avoid the “Do you want to install” question posed by the command above (esp. if you are writing a script to install), add the -y flag after the install option. To suppress all messages generated during the install, add the -qq flag after the install option

To remove a package

# apt-get remove {package-name}

When you use remove, it does not remove any dependencies that were installed along with the {package-name}. To remove these, run apt-get autoremove

The purge option combines two other options - remove and clean. The clean option removes the .deb package that was downloaded for installation.

# apt-get purge {package-name}

If you downloaded a .deb file and need to install it, use the dpkg command.

# dpkg -i /path/to/file.deb

An important point to note here, dpkg doesn’t install any dependencies. The -i flag notifies you of any missing dependencies, but you will have to install them manually. apt-get uses dpkg in the background to do the installation

To access an apt-get Easter egg, type apt-get moo at the command line and see for yourself

To search for any package, use the apt-cache command. If you are looking for all available versions of php, you could enter

# apt-cache search php

apt-cache also lets you list the packages already installed as

# apt-cache pkgnames

Please note that this list is really long as all base libraries are also displayed. The most common usage for me is to check if a particular library is installed and the version it is currently at, by piping the output of apt-cache to a grep

# apt-cache pkgnames | grep libmysqlclient

Adding Custom Repos

Some packages may be available on custom repositories, to include them for apt-get install, you first need to add the key for the repository using apt-key

# apt-key add {key-file}

Add the repository (the key file added previously is to verify that the source is a trusted one)

# apt-add-repository {url-of-repo}

The repo URLs are sometimes like regular HTTP(s) URLs and in some case a PPA (Personal Package Archive). So your add may look like this

# apt-add-repository https://deb.opera.com/

Or

# add-apt-repository ppa:gnome-desktop

Once you add a repo, run

# apt-get update

to refresh the list of available packages before running apt-get install

The alternate way to add new repo URLs is to edit the /etc/apt/sources.list

You may add this entry to add the opera repo to the sources.list file

deb https://deb.opera.com/opera-stable/ stable non-free

If you have lots of entries, you can create a .list file under /etc/apt/sources.list.d directory

Don’t forget to perform an apt-get update to refresh your package list

Other Package Managers

There are other flavors of Linux that use different package managers. For e.g., since Fedora 22, uses DNF (Dandified YUM) which is an enhanced version of YUM. It includes certain features like configuring new repos out of the box. The syntax is very similar to yum. Ubuntu/Debian also have another package manager called Aptitude (accessed as the command aptitude) which adds basic UI to package installation such as a progress bar. Other flavors have their own package managers, such as Arch Linux uses pacman. Whatever be your build, using a package manager eases the path to install and maintain your server, right from the base libraries to the custom applications you install.

Subscribe Email