Package management with your GNU/Linux distribution

From CLUG Wiki

Jump to: navigation, search

Contents

Debian based systems

dpkg: Depian Package Tool

Cloning the installed packages on a machine

On the machine you want to copy :

   dpkg --get-selections > package.list
 

Then on the newly created machine (which perhaps just has a base-install):

   dpkg --set-selections < package.list
   apt-get dselect-upgrade

APT: Advanced Package Tool

Debian uses APT (Advanced Package Tool). It is probably one of the most sophisticated and easy-to-use package managers in existence.

APT keeps a database of software that's available on local CD-ROM, hard disk, or the Internet. This list is usually available in the /etc/apt/sources.list file.

Debian based distributions use Debian packages with .deb extensions. Distributions that use .deb files and APT include: Debian Woody, Sarge and Sid, Ubuntu, Knoppix, and many others.

Debian Sources list

Typical entries in your sources.list file will look like this:

deb http://archive.ubuntu.com/ubuntu hoary main universe multiverse restricted
deb ftp://ftp.is.co.za/debian unstable main contrib non-free

You might have CD-ROM and hard disk entries as well, but more about that later.

apt-get update

The available packages on the Internet changes every day. To update your lists, type the following as root, or with sudo, depending on your setup:

root@debianbox# apt-get update

or

jonathan@debianbox$ sudo apt-get update

apt-get install

If you'd like to download a specific piece of software, in this case, Mozilla Firefox, you use the "apt-get install" command.

root@debianbox# apt-get install mozilla-firefox

apt-get remove

To remove a specific piece of software, such as exim, type:

root@debianbox# apt-get remove exim

If you want to be sure that all the config-files that go with it vanish too, stick a "--purge" in the middle:

root@debianobx# apt-get remove --purge exim

apt-get dist-upgrade

To update your entire debian-based system, you use 'apt-get dist-upgrade':

root@debianbox# apt-get dist-upgrade

If you want to leave it to download overnight, but not actually do any of the upgrading (because that would need to be monitored), stick a "-y --download-only" in the middle:

root@debianbox# apt-get -y --download-only dist-upgrade
Configuration updates

Debian prompts you whenever a configuration file that you have changed is about to be replaced by the file from a new version of the package. Stefano's magic trick for dealing with this situation is:

Configuration file `/etc/hdparm.conf'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
blah blah blah. I choose Diff (D)
*** hdparm.conf (Y/I/N/O/D/Z) [default=N] ? D

Now it displays the diff, and I can see that there is a change that I want to keep, but I want to incorporate the other changes that the package author made. So I choose background (Z) this time, and run vimdiff to merge the files:

# vimdiff /etc/hdparm.conf{,.dpkg-new}

The trick with vimdiff is (first to make sure that syntax highlighting is on - nice bright colours) then the keypress do replaces the bit that you are on with the bit on the other side of the screen. So just do that for all the changes that you want to merge into your configuration file.

Voila, a brand-spanking-new configuration file that still has your customisations.

apt-get clean

Clears out the local repository of retrieved package files. It removes everything but the lock file from /var/cache/apt/archives/ and /var/cache/apt/archives/partial/. When APT is used as a dselect method, clean is run automatically. Those who do not use dselect will likely want to run apt-get clean from time to time to free up disk space.

apt-get autoclean

Clears out the local repository of old useless package files. It removes packages which are no longer available and therefore useless. If you aren't the kind of person who runs apt-get clean then at least apt-get autoclean from time to time to save diskspace.

apt-cache search

If you'd like to search the APT database to see what packages are available, you can use the "apt-cache search" command:

joebloggs@debianbox$ apt-cache search firefox
libflash-mozplugin - GPL Flash (SWF) Library - Mozilla-compatible plugin
mozilla-firefox - lightweight web browser based on Mozilla
mozilla-firefox-dom-inspector - tool for inspecting the DOM of pages in Mozilla Firefox
mozilla-firefox-gnome-support - Support for Gnome in Mozilla Firefox
mozilla-firefox-locale-el - Mozilla Firefox Greek Language Package
mozilla-firefox-locale-es-ar - Mozilla Firefox spanish (es-AR) language/region package
mozilla-firefox-locale-es-es - Mozilla Firefox spanish (es-ES) language/region package
mozilla-firefox-locale-eu - Mozilla Firefox Basque language/region package

You will then see a list of packages containing the word "firefox".

apt-cache show

Then you want to find out about package "mozilla-firefox", so you type in

joebloggs@debianbox$ apt-cache show mozilla-firefox
Package: mozilla-firefox
Priority: optional
Section: web
Installed-Size: 26472
Maintainer: Eric Dorland <eric@debian.org>
Architecture: i386
Version: 1.0+dfsg.1-2
Provides: www-browser
Depends: fontconfig, psmisc, debianutils (>= 1.16), libatk1.0-0 (>= 1.7.2), libc6 (>= 2.3.2.ds1-4), libfontconfig1 (>= 2.2.1), libfreetype6 (>= 2.1.5-1), libgcc1 (>= 1:3.4.1-3), libglib2.0-0 (>= 2.4.7), libgtk2.0-0 (>= 2.4.4), libidl0, libjpeg62, libkrb53 (>= 1.3.2), libpango1.0-0 (>= 1.6.0), libpng12-0 (>= 1.2.8rel), libstdc++5 (>= 1:3.3.4-1), libx11-6 | xlibs (>> 4.1.0), libxext6 | xlibs (>> 4.1.0), libxft2 (>> 2.1.1), libxp6 | xlibs (>> 4.1.0), libxrender1, libxt6 | xlibs (>> 4.1.0), zlib1g (>= 1:1.2.1)
Suggests: mozilla-firefox-gnome-support (= 1.0+dfsg.1-2), latex-xft-fonts, xprt-xprintorg
Filename: pool/main/m/mozilla-firefox/mozilla-firefox_1.0+dfsg.1-2_i386.deb
Size: 9447680
MD5sum: f9351a51886b72244c8b3404dcce56df
Description: lightweight web browser based on Mozilla
 Firefox is a redesign of the Mozilla browser component, similar to
 Galeon, K-Meleon and Camino, but written using the XUL user interface
 language and designed to be lightweight and cross-platform.
 .
 This browser was previously known as Firebird and Phoenix.

apt-zip (for low- or no-bandwidth systems)

Instead of using apt-get upgrade you use apt-zip-list which creates a script on a diskette (or whatever) which you take (eg) to work and run there. The nice thing is that the script can run on any OS.

 eg: apt-zip-list -a upgrade -m /floppy
   - mounts /floppy and puts the script there
 or: apt-zip-list -a upgrade --skip-mount -m /tmp
   - puts the script in /tmp
 

All you need is to install the package apt-zip

The downloaded stuff (at work) can then be put onto flash or whatever in various forms eg tarball. Back at home you just run apt-zip-inst to complete the process...

If you use apt-proxy at home, then just put all the debs into say ~/debs and then use ...

 apt-proxy-import ~/debs
 ... to get them into the proxy. After that you can use apt-get as normal.

Aptitude

Aptitude is a real nice text interface tool that allows you to search and install packages easier. To launch Aptitude, type:

root@debianbox# aptitude

You can use the forward-slash button "/" on your keyboard to search for a package, and back-slash "\" to cycle through the results. If you want to select a package for installation, press the "+" button. To download and install your selections, press the "g" button two times.

Aptitude can also be run in command-line mode, very similarly to apt-get. The main advantage over apt-get is even better dependency handling. Example:

root@debainbox# aptitude install some-application

Synaptic

Synaptic is a simpler tool than Aptitude, but probably more apt (sorry- you'll start doing this too after a while) for newbie users.

You can normally find Synaptic in your GNOME/KDE/XFCE/etc menu. Alternatively, you can run "synaptic" with a run tool.

Red Hat based systems (Red Hat Enterprise & Fedora)

Red Hat Package manager

Red Hat uses RPM packages for their distributions. These include Red Hat Enterprise Linux and Fedora Core. The traditional Red Hat Linux range has been discontinued. Other systems, such as SuSE and Mandrake, also uses RPM, but they use slightly different implementations that evolved from the original Red Hat specification.

Red Hat has a graphical package manager that you can run from your GNOME or KDE menu's or by running redhat-config-packages (RHEL) or system-config-packages (Fedora).

APT for RPM

While Connectiva Linux was the first RPM based distribution to support APT, Redhat - and consequently, Fedora - followed shortly.

There are currently at least two meta-distributions of APT packages, both of them supporting the - in RedHat circles, at least - better known YUM as well.

In either case you may simply download the relevant "apt" RPM which contains all the required configuration files. After that it's a mere:

root@fedorabox# apt-get update

or

eroux@fedorabox$ sudo apt-get update

To update the repositories, followed by any of the "apt" commands mentioned in the Debian section.

Well known repositories

Off-hand, the following well-known RPM repostories for RedHat/Fedora exist:

  1. RPMForge: A collaboration of several well-known RPM repositories. You may get the "apt" RPM at http://apt.freshrpms.net/ or http://dag.wieers.com/home-made/apt/FAQ.php#B
  2. Fedora.us (APT and YUM) http://www.fedora.us/wiki/FedoraHOWTO

Synaptic

Synaptic can normally be obtained in either of the above mentioned repositories and, as mentioned above, allows for a simple, user friendly, interface to package management.

Yellow-dog Update Manager (YUM)

YUM is a tool similar to APT.

To install software using YUM, type:

[root@rhelbox]# yum install apache2

SuSE GNU/Linux

YaST: Yet another Setup Tool

SuSE also uses RPM. Probably the easiest way to install software with SuSE is to use YaST (Yet another Setup Tool)- considered by many to be _the_ setup tool. YaST has a graphical and text interface where you can search, select and install software. APT4RPM can also be installed, and YaST and APT will use the same database of software packages installed.

APT for RPM (apt4rpm)

Apt4rpm works almost exactly the same as the APT tool Debian use. See the Debian-based section above for more information on APT.

Also see the Download sources section for a little more on apt4rpm and SuSE.

Finding packages

SuSE includes a database of all packages part of the distribution on the first CD/DVD of the installation media. The database is in one file called ARCHIVES.tgz This file contains the names and locations of all available packages as well as the contents of all packages and all header information of the packages.

SuSE supply two tools to search through this database; YaST Software Installation Tool and pin. The YaST tool is described above and the Search tool has a number of different searching functions to help you find software quickly.

The pin tool is a command line tool that lets you search directly in the ARCHIVES.tgz file. It gives a more raw interface to the database than the YaST tool, but it also give more data. If you want to know if a file called libxyz.so is avaiable in a package, you open a terminal and type: pin libxyz.so

The tool will list all references to the file. This includes the package that will install the file as well as the location oof the file in the package.

If you search for a normal term, like editor, you will be swamped with results, as it will list the descriptions of all packages that contain the word editor as well as all files in packages that contain the word in thier path.

You can also just use zgrep on the ARCHIVES.tgz file. For example: zgrep editor ARCHIVES.tgz The pin tool is basically a frontend for zgrep, but the pin tool will also search installed packages.

SuSE's apt repositories also make use of an ARCHIVES.tgz file. So, you can download the file from the SuSE ftp server and search through all additional packages avalable via apt in the same manner.

Mandrake GNU/Linux

URPMI, URPME

Mandrake, like Redhat, uses RPM for package management. All standard rpm commands can be used to install, remove and generally manage RPMs. However Mandrake has also developed their RPM implementation further through the URPM tools. These tools will automatically manage and resolve dependancies which may exist between various packages for you.

To install software with URPM, you use the 'urpmi' command. The "i" stands for "install":

#urpmi evolution

To remove software with URPM, you use 'urpme'. The "e" stands for "erase".

#urpme twm

Additional urpm commands and examples

Search for a package:

#urpmq mozilla-firefox
#urpmq --fuzzy mozilla-

Get information on a package:

#urpmq -i mozilla-firefox

Add a media source:

#urpmi.addmedia contrib ftp://ftp.is.co.za/mirror/mandrivalinux/official/2006.0/i586/media/contrib with media_info/hdlist.cz 
#urpmi.addmedia --update update ftp://ftp.is.co.za/mirror/mandrivalinux/official/updates/2006.0/main_updates/ with media_info/hdlist.cz 

Update a media source:

#urpmi.update contrib
#urpmi.update -a

List media sources:

#urpmq –list-media

Remove a media source:

#urpmi.removemedia contrib

Update installed packages from update source:

#urpmi --auto-select --auto
#urpmi –update mozilla-firefox

To work through a proxy add these:

--proxy proxyserver.mydomain.com:3128 --proxy-user name:password

Mandrake Control Center (mcc)

You can install additional software using the Mandrake Control Center. This is probably the easiest way to add/remove software using Mandrake. Mandrake Control Center can also be run from the command line by typing 'mcc'.

Gentoo GNU/Linux

Unlike most other distributions that use pre-compiled binary packages to install software, Gentoo is a source-based distribution. The difference can be likened to buying a "ready-to-eat" hamburger (pre-compiled binary packages) vs. buying the ingredients to make a hamburger and making it yourself (source-based).

At the heart of Gentoo's package management is the system called Portage which is a collection of .ebuild files which you can think of "recipes" (to take the hamburder analogy a little further). When you install a package, Portage uses the .ebuild files to figure out where to get the source code for the package, how to compile the source code and where to install it.

Portage also features "USE flags", which are a mechanism for specifying optional features at installation time. For example if a package you want to install has an optional GUI interface, you may specify whether you want that optional feature installed or not.

Using Portage: the "emerge" command

Using Portage is mostly accomplished via the 'emerge' command. A few basic uses of emerge are described below.

Updating the Portage "tree"

The Portage "tree" is the collection of files, including .ebuild files, patches and others, that describe all the packages you can install. Each package in the portage tree is in a category (e.g. games-action for action games). From time to time you must update the copy of the Portage tree on your PC to ensure that you are not installing old packages. To update your Portage tree, use the command:

# emerge --sync

This will connect to one of Gentoo's Portage mirrors and update your Portage tree. Depending on the speed of your Internet connection and how long ago you've updated the tree, this should take between approximately 5 and 20 minutes.

Searching for a package

Sometimes you will want to search the Portage tree for a package, e.g. if you are not sure of the exact package name. Use the emerge --search switch:

emerge --search firefox
Searching...   
[ Results for search key : firefox ]
[ Applications found : 2 ]

*  net-www/mozilla-firefox
      Latest version available: 1.0
      Latest version installed: 1.0-r3
      Size of downloaded files: 31,920 kB
      Homepage:    http://www.mozilla.org/projects/firefox/
      Description: The Mozilla Firefox Web Browser
      License:     MPL-1.1 NPL-1.1

Here you can see that the Mozilla Firefox browser is in the net-www category, the package's name is mozilla-firefox and other useful information.

Installing packages & dependencies

To install software a package use the 'emerge' command as follows:

# emerge xfce4
# emerge xfce-base/xfce4
# emerge =xfce-base/xfce4/xfce4-4.0.6

This tells portage to follow the instructions for installing the xfce4 package. The first example only names the package, the second names the category and the package (necessary in some cases where duplicate package names exist in different categories) and the third example requests that a specific version of the package be installed. If the package depends on the presence of other packages (dependencies), Portage automagically figures this out and installs the dependencies first.

Using --pretend, --ask and --verbose

It is usually advisable to use the --pretend or --ask switch before installing a package, so you can see what package(s) Portage will install. Using --pretend causes the emerge command to display the package(s) that it will install. If you are satisfied with the --pretend output, simply run emerge without the --pretend switch. Using --ask is similar, except you will be prompted to go ahead and install, so you don't have to run emerge again.

Using the --verbose switch in conjunction with --pretend or --ask will cause emerge to display the USE flags supported by each package, the size of the files that need to be downloaded for each package and the total size of downloads.

The "system" and "world" classes

There are 2 special package names in Portage, system and world. These are technically known as classes. The system class refers to all packages installed as part of the base system, e.g. gcc and the Linux kernel. The world class refers to all packages included in the system class, as well as all other packages that you have installed in addition to the base system. You can update all the relevant packages in each class as follows:

# emerge --update system

OR

# emerge --update world

Uninstalling packages

To uninstall a package, use the --unmerge switch:

# emerge --unmerge doom3

Cleaning orphaned dependencies

Currently (26 Dec 2004) Portage does not remove any dependencies when you uninstall a package. This means that if you once installed the package "mypackage" and Portage automatically installed "someotherpackage" as a dependency, when you uninstall "mypackage", Portage will not uninstall "someotherpackage". You can clean orphaned dependencies using --depclean. Be very careful with --depclean as it can break your system if you're not careful. Always use --pretend first so you can check what will be removed:

# emerge --pretend --depclean

If you are satisfied that the listed packages can be safely removed, then:

# emerge --depclean

Further reading

Be sure to check out 'man portage' and 'man emerge', as well as the Working With Portage section in the Gentoo Handbook

Slackware based systems

pkgtool

Slackware is one of the oldest GNU/Linux distrubutions. It is considered to be closest to traditional UNIX. It doesn't have a big package management system such as Debian-Package (DPKG) or Red Hat Package Manager (RPM). Instead, it extracts all the files in an archive to the appropriate place and runs a configuration script, which isn't too far from what RPM and DPKG does. The difference is that pkgtool doesn't do much (if any) dependency checking. It doesn't keep a proper database of installed software either.

Pkgtool is fairly easy to use. Simply run "pkgtool" from the command line and it will guide you through installing software.

The beauty of Slackware lies in its simplicity. You can have a real small operating system that does the specific task, without extra bloat (such as apt or rpm :) ). This can result in improved security, and performance. Even though Slackware is a great server distro, it also works well on desktop systems. The lack of a fancy package manager doesn't make Slackware the ideal distro for a beginner user.

Other Slackware based systems: Slax, DireqLearn OpenLab