Hosting Websites on Bare Minimum VPS/Dedicated Servers

Package Management Walkthrough: apt, yum, dnf, pkg

Tags: , , , , , , , , Date/Time: June 29, 2019 @ 9:22 am, by Dusko Savic

In this tutorial, we will give you an overview of package management utilities on Ubuntu and Debian, Centos, Fedora, and FreeBSD. Once you install, say, Apache and Nginx, PHP, a MySQL database, all these systems start behaving similarly. The main difference is located in the tools for package management and that is how most newcomers to VPS boxes decide which server to run their sites and applications on.

What We Are Going To Cover

  • apt utility for Debian and Ubuntu
  • yum for Centos
  • DNF for Fedora
  • pkg for FreeBSD

and for each of these will show how to

  • find help / read manual,
  • install a package,
  • delete it,
  • find package in a repository,
  • eventually check for vulnerabilitiesand so on.

Prerequisites

If you want to try out the commands, you will need

  • root user access as well as the ability to
  • SSH into the VPS.

Basic Functions of Package Managers

Windows users download their applications from web sites and each app is then responsible for the upgrades and security patches. Linux is different: all applications wait in so-called repositories to be downloaded and installed. Programs that download and install the packages are called package managers and each Linux distribution will have its own repository and the corresponding package manager. For more popular systems, such as Ubuntu, there are repositories for each major version, say, 14.04, 16.04 and so on. The so-called backport repositories may exist as well, when a newer version of the package, say from Ubuntu version 16.04, is ported “back” to the repository for Ubuntu version 14.04.

Unlike Windows users, on Linux you would not even care which version is installed. The package manager would choose the proper version and see to the rest of the process. Some software companies deliver installation files directly, on Debian for example, but there are lower level commands to handle such cases as well.

Package manager can search the repository so that you can see whether the package you want to install is there. It is also possible to test what would change in the system if you installed a package, which may be of vital importance in certain cases.

The same package manager can remove the installed package from system cache, and can also deinstall the app, completely. If there is a newer version in the repository then in the VPS, the package can be upgraded on the run.

APT for Debian / Ubuntu

For Debian-like systems, including Ubuntu, the basic high level package manager is called apt. Its lower level counterpart, for dealing with particular files is called dpkg. File type is .deb.

apt is a relatively new service, and gained prominence with Ubuntu 16.04. The name of the package manager that was used previously is apt-get. To make things even more confusing, the set of tools that Debian uses to manage packages is called APT — which is not the apt that we are talking here about.

apt was introduced to simplify package management for normal users. It has more default values and is easier to use than apt-get. apt-get, however, is not going anywhere and can still be used without problems. In this tutorial, we are going to use apt only.

How To Get Help About apt Package Manager

The command to read documentation about apt is

apt help

You will have the most popular commands at a glance:

How To Upgrade the Server

Package managers read files from the repository into the systems cache. The command is:

sudo apt update

Run that on Debian box. Dozens of lines of output will be produced, ending with

Notice it says there are 3 packages to be upgraded. Run

apt list --upgradable

to see the complete list.

Running the same upgrade command on Ubuntu 19.0 will produce a different outcome:

Under Ubuntu, there will be 65 packages to upgrade.

The entire server version will be updated with:

sudo apt upgrade

The command

sudo apt full-upgrade

will perform full upgrade, which means that the conflicting package dependencies will be upgraded to the newest version, removing older or unused dependencies at the same time.

Update and Upgrade In One Line

Following along recipes for installation of software for your VPS, you will frequently see the following line:

sudo apt update && sudo apt upgrade

which both updates and upgrades the server. That way, you are guaranteed to have the latest version of software for the installation.

Installing Software

You can search for the software to install:

sudo apt search packageName

The result may not be that usable, as it may consist of dozens of lines of available packages. You may want to copy the contents of the terminal window into a text editor and there search for the package name.

To install software, the command is:

sudo apt install packageName

For example, running

sudo apt install perl

on Debian let me install one new module for programmins language perl, while on Ubuntu nothing needed to be installed as

perl is already the newest version (5.28.1-6).

apt cannot install software from a URL, but the lower level package RPM can. Installing from the repositories is always safer, though.

Removing Packages With apt

To remove a package:

sudo apt remove packageName

apt will remove unused dependencies, but in case some still remain, here’s another command:

sudo apt autoremove

How to list all installed packages:

apt list --installed

Yum Package Manager On Centos

yum is the package manager for Centos, a security oriented version of Red Hat Linux. File format is .rpm. yum installs or upgrades any package dependencies, which is the main benefit from using it. yum wil download packages from the official repositories, but you can also set up your own repositories on systems that do not have Internet access.

How To Get Help About yum Package Manager

Run

yum help

The first screen lists all commands:

The second screen shows available parameters for yum:

How To Upgrade the Server With Yum

The update command of Yum both upgrades and updates the system:

sudo yum update

Even if your server installation is just one day old, as is the case here, there will be something new to upgrade and install:

It will ask you for approval, once or twice; answer Y if you want the installation to proceed.

WARNING: For longer transactions, it may appear that the terminal is dead (nothing happens in its window). Be patient and wait it out. Otherwise, when another transaction is set in motion, Centos will ask you to finish the previous transaction first. Or, you can clean up with the command such as:

yum-complete-transaction --cleanup-only

Installing Software With Yum

To search for an installable package:

sudo yum search packageName

Install a package with the following command:

sudo yum install packageName

NOTE: yum will ALWAYS install the latest version of the kernel.

Removing Packages with yum

Remove a package with:

sudo yum remove packageName

yum includes three commands for removing the packages:

  • autoremove will completely erase any traces of the previous configuration.
  • remove will maintain a local copy of any configuration files/directories that were changed from the default values during the installation.
  • erase is the same as remove.

DNF Package Manager on Fedora

While Centos is a free version of Red Hat Linux, Fedora is like a laboratory for research and development for those two systems. As of Fedora version 22, DNF has replaced yum as the official package manager and it is likely that one day the same will happen on Centos. DNF should serve as the improved version of yum so the commands will be similar.

With DNF, maintaining groups of machines is made easier, so you do not need to manually update each one using rpm. It also

  • supports multiple repositories
  • uses depsolving technology for dependency calculations
  • runs faster and takes less memory than yum
  • treats .RPM files consistently
  • is written in Python and runs on both Python 2 and Python 3
  • has its own plugins, which can modify its behavious and introduce new commands.

How To Get Help About DNF Package Manager

The command is:

dnf help

Here is a list of the main commands that it supports:

And this is the list of plugins and a partial list of optional arguments:

How To Upgrade the Server With DNF

To update and upgrade all software:

sudo dnf update

As usual, answer with Y when asked whether you want to proceed with the installation.

There also is a command

dnf check-update

but you do not need to do this as DNF updates its cache automatically before performing transactions.

Installing Packages with DNF

Search for an installable package:

sudo dnf search packageName

To install a package:

sudo dnf install packageName

Removing Packages with DNF

To remove a package:

sudo dnf remove packageName

The autoremove command will search across the system and remove unused dependencies:

sudo dnf autoremove 

This is the warning it sent me:

so be sure to always add the name of the package you want autoremoved:

sudo dbf autoremove packageName

Differences Between apt and BNF Commands

Here is a comparison between apt and DNF commands:

Ubuntu command Fedora command
apt update dnf check-update
apt upgrade dnf upgrade
apt dist-upgrade dnf system-upgrade
apt install dnf install
apt remove dnf remove
apt purge N/A
apt-cache search dnf search

 

Package Management With PKG On FreeBSD

FreeBSD has two ways of installing software:

  • packages, which is similar to installing .deb packages on Ubuntu / Debian and .rpm on Centos / Fedora, and
  • ports which is making software from source, and is not further explained in this tutorial.

The main difference is that pkg will install only the binary packages.

How To Get Help About pkg Package Manager

The command is

pkg help

How To Upgrade the Server With pkg

freebsd-update fetch install
pkg update && pkg upgrade

Press Y when asked whether to install.

Installing Packages with pkg

Search for a package:

pkg search packagename

Install a package:

pkg install packagename

Here is what installing nginx looks like:

List installed packages:

pkg info

Upgrade from remote repository:

pkg upgrade

Delete an installed package:

pkg delete packageName

Checking Dependencies

Check for missing dependencies:

pkg check -d -a

Remove unneeded dependencies:

pkg autoremove

Automatic And Non-automatic Packages

List non-automatic packages:

pkg query -e '%a =    0' %o

List automatic packages:

pkg query -e '%a =    1' %o

Change a package from automatic to non-automatic, which will prevent autoremove from removing it:

pkg set -A 0 packageName

Change a package from non-automatic to automatic, which will make autoremove it be removed once nothing depends on it:

pkg set -A 1 packageName

Security Advisories

Audit installed packages for security advisories:

pkg audit

And here is the result:

The audit command goes to the vulnerability database for FreeBSD and reads from there. Here is what it’s readable form looks like:

We should now wait for the upgraded version to appear and then use the upgrade command to patch it.

Dusko Savic is a technical writer and programmer.

duskosavic.com

No Comments

Leave a Reply

Some notes on commenting on LowEndBox:

  • Do not use LowEndBox for support issues. Go to your hosting provider and issue a ticket there. Coming here saying "my VPS is down, what do I do?!" will only have your comments removed.
  • Akismet is used for spam detection. Quoting webhostingtalk.com URL seems to get binned consistently here, but I do peek into the spam box frequently to publish those comments.
  • Use <pre>...</pre> to quote the output from your terminal/console, or consider using a pastebin service.

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