# Managing Packages
Package Management is the subsystem that allows you to install, upgrade or
remove software from your system. Linux offers a variety of different package
management systems. For the purpose of our intro we will focus on two popular
ones apt
and yum
. Used by Debian and RedHat based/like distributions
respectively. Be aware that most actions concerning packages require root
access. I will skip the sudo
in front of each command and let you figure out
what that means.
# APT
In Debian based systems the lowest level of package interaction is done via
dpkg
which can be a tricky command for novice users. To help newbies along
their path the advanced package tool apt
serves as a frontend to dpkg
and
makes managing packages easier. We would not be in the Linux world if there
would not be some alternatives. Most notably aptitude
and for the GUI lovers
synaptic
. By convention packages meant for Debian have an extension of .deb
.
# Installing Software
apt
by default accesses the Debian repositories, which host multiple
ten-thousands of packages. To update the list of available packages you use the
apt-get
command like this
apt-get update
Searching for a specific package in apt's cache is similarity intuitive
apt-cache search keyword
Installing is done via apt-get install
.
TIP
Go on and install something fancy, lets say the latest ruby with development headers that is available in the repository.
A side note here. If you are trying to install software you already have it will be updated if there is a new version available or nothing will be changed.
# Keeping up-to-date
Upgrading all installed software to the latest version is fairly simple
apt-get update
apt-get upgrade
2
At some point in time you will notice that upgrade
warns you about some
packages that have been kept back.
This is the time to acquaint yourself with dist-upgrade
. Roughly speaking dist-upgrade
will handle some upgrades
that upgrade
is to conservative for.
For example it will perform upgrades that require the removal or installation of
additional packages. The reasoning here is that upgrade
should under all
circumstances avoid breaking things. Note that while this holds for upgrade
it might not hold for the software you are upgrading.
# Removing Software
Removing a package might result in cascading removal due to dependencies. That is if package A depends on B and you remove B then A will also be removed. The same holds true for everything depending on B, so removal is a transitive operation. To remove a package simply
apt-get remove package-name
This will remove the package but keep the configuration files.
TIP
Go ahead and figure out how to remove those as well.
Hint: There are at least 3 solutions two of which are not nasty.
# dpkg magic
For more advanced interaction lets dive a bit deeper and interact with dpkg directly.
Command | Meaning |
---|---|
dpkg -l | List all packages installed on a system |
dpkg -L package | List all files of a package |
dpkg -S /path/to/file | Show which package a file belongs to |
TIP
Now go and find out which package id
belongs to and how dpkg reacts if you
try doing the same thing for a random log file.
# YUM
Like apt
, yum
is a frontend to a more basic package management system rpm
.
rpm
is mainly used by RedHat and its derivates but can also be found in non
RedHat distributions like SuSe. Alternatives include up2date
or if you like
visuals yumex
.
# Installing Software
Use yum search
and yum install
to get your packages.
# Keeping up-to-date
For individual packages use yum update package
or just type yum update
to update everything that there is to update.
Be aware that the philosophy between Debian and RedHat is very different when it
comes to updates. If you want to update everything but exclude the kernel modules you
would need to run yum update
with an option.
TIP
Go and figure out which option that is.
In addition read up on yum upgrade
and what it does for you.
# Removing Software
As you would expect yum remove package
will remove the given package and
related dependencies.
TIP
Figure out what rpm
would do.
Also find out what happens to configuration files on package removal with yum
and rpm
.
# rpm magic
As with dpkg
lets dive into some backend features. Interacting with rpm
directly will save you the overhead of some network request if your actions are
only interacting with local packages.
Command | Meaning |
---|---|
rpm -qa | List all packages installed on a system |
rpm -ql package | List all files of a package |
rpm -qi package | Get information on a package |
rpm -qf /path/to/file | Show which package a file belongs to |