Chapter 9

Managing Software

In this chapter, we look at the options for managing your software in Ubuntu. If you are used to an environment where you are reliant on visiting different vendor websites to download updates, you are in for a pleasant surprise. Updating a full Ubuntu installation, including all the application software, is as simple as running the Update Manager program. You will discover just how easy it is to install and even remove various software packages.

Ubuntu provides a variety of tools for system resource management. The following sections introduce the graphical software management tools you will use for most of your software management. This chapter also covers monitoring and managing memory and disk storage on your system.

Ubuntu Software

Ubuntu Software is a graphical utility for package management in Ubuntu. You can find it by searching Activities for “Ubuntu Software”; the package and executable program is named ubuntu-software. Ubuntu Software enables you to easily select and install a large array of applications by using the intuitive built-in search and easy one-click installation. When you open the program, you see the main screen, as shown in Figure 9.1.

Images

FIGURE 9-1 The initial Ubuntu Software screen enables you to browse through packages sorted into categories.

Along the top side of the screen, you have three menu options: All, Installed, and Updates. To the right is a search icon you can use to search for packages. Scroll down to find software listed by categories.

Installing new software via Ubuntu Software is as simple as finding the software in the package list, double-clicking it, and then clicking the Install button. When you do so, you may be asked for your password; then the application is downloaded and installed. You can remove an application by finding it in Ubuntu Software and clicking the Remove button.

Using Synaptic for Software Management

Ubuntu Software works just fine for adding and removing applications, but if you need to install something specific—such as a library—you need to use the command line or Synaptic (see Figure 9.2). You can install Synaptic by using Ubuntu Software; it is not installed by default.

Images

FIGURE 9-2 For more advanced software management in a GUI, Synaptic is the preferred tool.

Along the left are software categories, along the top right are the package selections for that category, and on the bottom right is the Package Information window, which shows information about the currently selected package. To install or remove software, click the check box to the left of its name, and you see a menu that offers the following options:

Unmark—If you have marked the package for installation, upgrade, or one of the other options, this option removes that mark.

Mark for Installation—Click this option to add this package to the list that will be installed.

Mark for Re-installation—If you have some software already installed, but for some reason it’s not working, click this option to reinstall it from scratch. Existing configuration files are retained, so any edits you have made are safe.

Mark for Upgrade—If the software has updates available, select this option to download and install them.

Mark for Removal—Select this option to delete the selected package from your system but leave its configuration files intact so that if you ever reinstall it, you do not have to reconfigure it.

Mark for Complete Removal—Select this option to delete the selected package from your system and also remove any configuration files and purge everything from the system.

After you have made your changes, click the Apply button to have Synaptic download, install, upgrade, and uninstall as necessary. If you close the program without clicking Apply, your changes are lost.

Beneath the categories on the left side of the screen are six buttons: Sections, Status, Origin, Custom Filters, Search Results, and Architecture. These customize the left list: Sections is the Categories view; Status enables you to view packages that are installed or upgradable; Origin lists the different repositories available to download packages; Custom Filters has some esoteric groupings that are useful only to advanced users; Search Results stores results of your searches; and Architecture shows the packages specific to each architecture of Ubuntu.

You can press Ctrl+F at any time to search for a particular package. By default, it is set to search by package description and name. You may change the Look In box setting to only search for name. As mentioned earlier, your search terms are saved under the Search view (the button on the bottom left), and you can click from that list to search again on that term.

As well as providing the method of installing and removing software, Synaptic provides the means to configure the servers you want to use for finding packages. In fact, this is where you can make one of the most important changes to your Ubuntu system: You can open it up to the Ubuntu Universe and Multiverse.

Ubuntu is based on the Debian distribution, which has thousands of software packages available for installation. Ubuntu uses only a subset of that number but makes it easy for you to install the others, along with many packages that are not available in Debian. When you use Synaptic, you see small orange Ubuntu logos next to many packages, which identify them as being officially supported by the Canonical-supported Ubuntu developers. The packages that do not have this logo are supported by the wider Ubuntu community of developers.

To enable the Universe and Multiverse repositories, go to Settings, Repositories. This list shows all the servers you have configured for software installation and updates and includes the Universe and Multiverse repositories. When you find them, check them, and then click Close.

Synaptic shows a message box, warning you that the repository listings have changed and that you need to click the Reload button (near the top left of the Synaptic window) to have it refresh the package lists. Go ahead and do that, and you should see a lot more software options appear for your selection. However, notice that only some software options have the official Ubuntu seal attached, and for anything that does not have the seal, you may want to be cautious when installing it.

Note

Much of the software discussed in this book is available only through the Universe repository. Therefore, we highly recommend enabling it to get full use out of this book and your Ubuntu installation.

Staying Up to Date

Although you can manage your software updates through Synaptic, Ubuntu provides a dedicated tool called Software Updater (shown in Figure 9.3). This tool is designed to be simple to use: When you run it, Software Updater automatically downloads the list of updates available and checks them all in the list it shows. All you need to do is click Install Now to bring your system up to date. If you want a little more information about the updates, click Technical Description to see what has changed in the update.

Images

FIGURE 9-3 If you need to update your software to apply bug fixes and security upgrades, use Software Updater.

Ubuntu automatically checks for updates periodically and notifies you when critical updates are available. However, there’s no harm in running Software Updater yourself every so often, just to make sure; it’s better to be safe than sorry.

Working on the Command Line

With so much software available for installation, it is no surprise that Debian-based distros provide many ways to manage software installation. At their root, however, they all use Debian’s world-renowned Advanced Package Tool (APT). A person posting on Slashdot.com once said, “Welcome to Slashdot. If you can’t think of anything original, just say how much APT rocks and you’ll fit right in.” You see, even though many other distros have tried to equal the power of APT, nothing else even comes close.

Why is APT so cool? Well, it was the first system to properly handle dependencies in software. Other distros use files that have dependencies. For example, Red Hat used RPM files that had dependencies. An RPM for GIMP would have a dependency on GTK, the graphical toolkit on which GIMP is based. As a result, if you tried to install your GIMP RPM without having the GTK RPM, your install would fail. So, you grab the GTK RPM and try again. Aha: GTK has a dependency on three other things that you need to download, and those three other things have dependencies on 20 other things…and so on, usually until you can’t find a working RPM for a dependency, and you give up.

APT, on the other hand, was designed to automatically find and download dependencies for your packages. So, if you want to install GIMP, APT downloads GIMP’s package and any other software it needs to work. No more hunting around by hand, no more worrying about finding the right version, and certainly no more need to compile things by hand. APT also handles installation resuming, which means that if you lose your Internet connection partway through an upgrade (or if your battery runs out, or if you have to quit, or whatever), APT picks up where it left off the next time you run it.

Day-to-Day APT Usage

To enable you to search for packages both quickly and thoroughly, APT uses a local cache of the available packages. Try running this command:

matthew@seymour:~$ sudo apt update

The apt update command instructs APT to contact all the servers it is configured to use and download the latest list of file updates. If your lists are outdated, it takes a minute or two for APT to download the updates. Otherwise, this command executes it in a couple of seconds.

After the latest package information has been downloaded, you are returned to the command line. You can now ask APT to automatically download any software that has been updated, using this command:

matthew@seymour:~$ sudo apt upgrade

If you have a lot of software installed on your machine, there is a greater chance of things being updated. APT scans your software and compares it to the latest package information from the servers and produces a report something like this:

mmatthew@seymour:~$ sudo apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be upgraded:
  cabextract google-chrome-beta icedtea6-plugin language-pack-en
  language-pack-en-base language-pack-gnome-en language-pack-gnome-en-base
  libfreetype6 libfreetype6-dev libsmbclient libwbclient0 openjdk-6-jre
  openjdk-6-jre-headless openjdk-6-jre-lib samba-common samba-common-bin
  smbclient upstart winbind xserver-common xserver-xorg-core
21 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 84.8MB of archives.
After this operation, 623kB of additional disk space will be used.
Do you want to continue [Y/n]?

Each part of this report tells you something important. Starting at the top, the line, “The following packages will be upgraded,” gives you the exact list of packages for which updates are available. If you’re installing new software or removing software, you see lists titled, “The following packages will be installed” and “The following packages will be removed.” A summary at the end shows a total of 21 packages that APT will upgrade, with 0 new packages, 0 to remove, and 0 not upgraded. Because this is an upgrade rather than an installation of new software, all those new packages take up only 623KB of additional space. Although you have an 84.8MB download, the packages are overwriting existing files.

It’s important to understand that a basic apt upgrade never removes software or adds new software. As a result, it is safe to use this command to keep your system fully patched because it should never break things. However, occasionally you will see the “0 not upgraded” status change, which means some things cannot be upgraded. This happens when some software must be installed or removed to satisfy the dependencies of the updated package, which, as previously mentioned, an apt upgrade never does. In this situation, you need to use apt dist-upgrade, so named because it’s designed to allow users to upgrade from one version of Debian/Ubuntu to a newer version—an upgrade that inevitably involves changing just about everything on the system, removing obsolete software, and installing the latest features. This is one of the most-loved features of Debian because it enables you to move from version to version without your having to download and install new CDs. Keeping regular upgrades and distro upgrades separate is very useful for making sure that security updates and simple bug fixes don’t change software configurations that you may be counting on, especially on a machine that needs to be consistently available and working, such as a server.

Whereas apt upgrade and apt dist-upgrade are available for upgrading packages, apt install is responsible for adding new software. For example, if you want to install the MySQL database server, you run this:

matthew@seymour:~$ sudo apt install mysql-server

Internally, APT queries mysql-server against its list of software and finds that it matches the mysql-server-5.7 package. It then finds which dependencies it needs that you don’t already have installed and gives you a report like this one:

matthew@seymour:~$ sudo apt install mysql-server
[sudo] password for matthew:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libaio1 libevent-core-2.1.6 libhtml-template-perl mysql-client-5.7
  mysql-client-core-5.7 mysql-common mysql-server mysql-server-5.7
  mysql-server-core-5.7
Suggested packages:
  libipc-sharedcache-perl tinyca mailx
The following NEW packages will be installed:
  libaio1 libevent-core-2.1.6 libhtml-template-perl mysql-client-5.7
  mysql-client-core-5.7 mysql-common mysql-server mysql-server-5.7
  mysql-server-core-5.7
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 20.3 MB of archives.
After this operation, 160 MB of additional disk space will be used. Do you want to continue [Y/n]?

This time, you can see that APT has picked up and selected all the dependencies required to install MySQL Server 5.7, but it has also listed one recommended package and two suggested packages that it has not selected for installation. The “recommended” package is just that: The person who made the MySQL package (or its dependencies) thinks it would be a smart idea for you to also have the mailx package. If you want to add it, press N to terminate apt and rerun it like this:

matthew@seymour:~$ sudo apt install mysql-server mailx

The “suggested” packages are merely a lower form of recommendation. They don’t add any crucial features to the software you selected for install, but it’s possible that you might need them for certain noncrucial (to the main piece of software being installed) features or tasks.

Note

APT maintains a package cache where it stores DEB files it has downloaded and installed. This usually lives in /var/cache/apt/archives and can sometimes take up many hundreds of megabytes on your computer. You can have APT clean out the package cache by running apt clean, which deletes all the cached DEB files. Alternatively, you can run apt autoclean, which deletes cached DEB files that are beyond a certain age and keeps newer packages.

If you try running apt install with packages you already have installed, APT considers your command to be apt update and looks to see whether new versions are available for download.

Another important day-to-day package operation is removing things you no longer want, which you do by using the apt remove command, as follows:

matthew@seymour:~$ sudo apt remove firefox

Removing packages can be dangerous because APT also removes any software that relies on the packages you selected. For example, if you were to run apt remove libgtk2.0-0 (the main graphical toolkit for Ubuntu), you would probably find that APT insists on removing more than 100 other things. The moral of the story is this: When you remove software, read the APT report carefully before pressing Y to continue with the uninstall.

A straight apt remove leaves behind the configuration files of your program so that if you ever reinstall it, you do not also need to reconfigure it. If you want to remove the configuration files as well as the program files, run this command instead:

matthew@seymour:~$ sudo apt remove -purge firefox

Or run this:

matthew@seymour:~$ sudo apt purge firefox
Both of these commands will perform a full uninstall.

Note

You can see a more extensive list of apt parameters by running apt without any parameters. The cryptic line at the bottom, “This APT has Super Cow Powers,” is made even more cryptic if you run the command apt moo.

Finding Software

With so many packages available, it can be hard to find exactly what you need by using APT at the command line. The general search tool apt-cache is used like this:

matthew@seymour:~$ apt-cache search kde

Depending on which repositories you have enabled, the tool returns about 1,000 packages. Many of those results do not even have KDE in the package name but are matched because the description contains the word KDE.

You can filter through this information in several ways. First, you can instruct apt-cache to search only in the package names, not in their descriptions by using the –n parameter, like this:

matthew@seymour:~$ apt-cache –n search kde

Now the search goes down from more than 1,000 packages to a few hundred.

Another way to limit search results is to use some basic regular expressions, such as ^, meaning “start,” and $, meaning “end.” For example, you might want to search for programs that are part of the main KDE suite and not libraries (usually named something like libkde), additional bits (such as xmms-kde), and things that actually have nothing to do with KDE yet still match the search (for example, tkdesk). Do this by searching for packages that have a name starting with kde, as follows:

matthew@seymour:~$ apt-cache –n search ^kde

Perhaps the easiest way to find packages is to combine apt-cache with grep to search within search results. For example, if you want to find all games-related packages for KDE, you can run this search:

matthew@seymour:~$ apt-cache search games | grep kde

When you’ve found the package you want to install, run it through apt install as usual. If you first want a little more information about that package, you can use apt-cache showpkg, like this:

matthew@seymour:~$ apt-cache showpkg mysql-server-5.7

This shows information on “reverse depends” (which packages require, recommend, or suggest mysql-server-5.7), “dependencies” (which packages are required, recommended, or suggested to install mysql-server-5.7), and “provides” (which functions this package gives you). The “provides” list is quite powerful because it allows different packages to provide given resources. For example, a MySQL database-based program requires MySQL to be installed, but it isn’t fussy about whether you install MySQL 4.1 or MySQL 5.7. In this situation, the Debian packages for MySQL 4.1 and MySQL 5.7 would both have mysql-server-4.1 in the provides list, meaning that they would offer the functionality provided by MySQL 4.1. Therefore, you could install either version to satisfy the MySQL-based application.

Using apt-get Instead of apt

While the new, simplified interface to APT that removes the hyphen and the second part of the command works great and includes lovely updates like a progress bar, it does not yet include all functionality of the venerable apt-get. Table 9-1 lists some of the new commands and what they replace, in case you are more familiar with the old commands. Both versions work, so no relearning is necessary if you do not want to switch. Today, apt-get is used only for much more advanced package management tasks beyond the needs of what we cover in this book.

Table 9.1 apt-get Versus apt

apt-get Command

apt Command

apt-get install

apt install

apt-get remove

apt remove

apt-get update

apt update

apt-get upgrade

apt upgrade

apt-get dist-upgrade

apt full-upgrade

apt-get remove --purge

apt purge

apt-get autoremove

apt autoremove

apt-get search

apt search

apt-get show

apt show

dpkg --get-selections

apt list --installed

apt-get purge

apt purge

Compiling Software from Source

Compiling applications from source is not difficult. There are two ways to do it: You can use the source code available in the Ubuntu repositories, or you can use source code provided by upstream developers (which is most useful for projects that are not available in the Ubuntu repositories). For either method, you need to install the build-essential package to ensure that you have the tools you need for compilation. You may also need to install automake and checkinstall, which are build tools.

Compiling from a Tarball

Most source code that is not in the Ubuntu repositories is available from the original writer or from a company’s website as compressed source tarballs—that is, tar files that have been compressed using gzip or bzip. The compressed files typically uncompress into a directory containing several files. It is always a good idea to compile source code as a regular user to limit any damage that broken or malicious code might inflict, so create a directory named source in your home directory.

From wherever you downloaded the source tarball, uncompress it into the ~/source directory by using the -C option to tar:

matthew@seymour:~$ tar zxvf packagename.tgz -C ~/source
matthew@seymour:~$ tar zxvf packagename.tar.gz -C ~/source
matthew@seymour:~$ tar jxvf packagename.bz -C ~/source
matthew@seymour:~$ tar jxvf packagename.tar.bz2 -C ~/source

If you are not certain what file compression method was used, use the file command to figure it out:

matthew@seymour:~$ file packagename

Now, change directories to ~/source/packagename and look for a file named README, INSTALL, or something similar. Print out the file, if necessary, because it contains specific instructions on how to compile and install the software. Typically, the procedure to compile source code is as follows:

matthew@seymour:~/source/packagename$ ./configure

This runs a script to check whether all dependencies are met and whether the build environment is correct. If you are missing dependencies, the configure script normally tells you exactly which ones it needs. If you have the Universe and Multiverse repositories enabled in Synaptic, chances are you will find the missing software (usually libraries) in there.

When your configure script succeeds, run the following to compile the software:

matthew@seymour:~/source/packagename$ make

Finally, run the following:

matthew@seymour:~/source/packagename$ sudo make install

If the compile fails, check the error messages for the reason and run the following before you start again:

matthew@seymour:~/source/packagename$ make clean

You can also run the following to remove the software if you do not like it:

matthew@seymour:~/source/packagename$ sudo make uninstall

Compiling from Source from the Ubuntu Repositories

You might sometimes want to recompile a package, even though a binary package is available in the Ubuntu repositories. For example, a program might have been compiled into a binary with a specific feature disabled that you would like to use. Here is how you can do this, using a software package named foo that you want to compile.

First, get the source from the Ubuntu repositories:

matthew@seymour:~$ apt source foo

Install the build dependencies for the package:

matthew@seymour:~$ sudo apt build-dep foo

Change to the directory for the source code (which may include the version number):

matthew@seymour:~$ cd foo-4.5.2

Make whatever changes you want to make to the package or to the compilation flags. You can do this by using ./configure and make, or sometimes you can make manual changes to a configuration file. Each package has the potential to do this differently, so you need to see that program’s documentation. Try looking for a README file in the source code to get started.

Next, create a new debian/changelog entry. After you enter this command, you need to enter a message that tells why a new version was made, perhaps something like Matthew’s flight of fancy with extra sauce.

matthew@seymour:~$ dch -i

Note

Ubuntu package numbering follows a specific pattern. To help yourself later, you should stick to this pattern. Using the foo numbers shown here, a typical Ubuntu package that was inherited from Debian with no changes would then be 4.5.2-1. A package inherited from Debian but changed for Ubuntu would be 4.5.2-1ubuntu1 (and then ubuntu2 for a second version, and so on). A package that did not have a version in Debian but which was created for Ubuntu would be 4.5.2-0ubuntu1 (and ubuntu2 and so on).

Build the source package. This creates all the files necessary for uploading a package:

matthew@seymour:~$ debuild -S

Finally, you are left with a foo-4.5.2-1ubuntu1custom.deb package (using whatever version number or suffix you created earlier) that you can install—and later uninstall as well—using your package manager. In some instances, multiple DEB files might be created, in which case you replace the individual package name in the example here with *.deb:

matthew@seymour:~$ sudo dpkg -Oi foo-4.5.2-1ubuntu1custom.deb

Configuration Management

This section provides a quick introduction to a couple tools that might be useful to you if you want more control over system configuration management. For larger needs, see Chapter 33, “Managing Sets of Servers.”

dotdee

If you run Linux-based systems, you will find a series of directories that end with a .d and that store configuration files. These are sometimes called .d or “dotdee” directories. If you look in /etc/, you find many such directories (such as apparmor.d and pam.d). Opening these directories reveals a large number of configuration files and perhaps other directories containing even more. In Ubuntu or other Debian-based systems, it is a violation of etiquette (and Debian policy) for any software package to be allowed to directly change the configuration files of another package. This can be problematic if you want to use system configuration management software.

dotdee solves this problem by allowing you to replace any flat file in your file system with a symlink pointing to a file that is generated from a .d-style directory. It saves the original file and then updates the generated file automatically and dynamically any time any file in the original .d directory is added, deleted, or modified. This way, the Debian policy and general etiquette standards are met, but configurations can be modified as needed by an external program.

dotdee works its magic using inotify to dynamically and instantly update the master file. The master file can be built three different ways: using flat files, which are concatenated; using diff/patch files, which are applied in a quiltlike manner; and using executables, which process stdin and dump to stdout. This flexibility should make any system administrator or developer guru happy.

Ubuntu Core

Ubuntu Core adds the absolute minimum of files and code necessary for a usable Ubuntu server image to it as a new means of managing software packages. The idea is similar to how smart phones like Android-based phones provide software: The software packages include everything they need to run on the operating system, effectively making it so that a package is isolated from the operating system more completely. This is designed to protect against the possibility of a package breaking other packages or an entire operating system installation. It is also intended to make updates easier and cleaner for use cases like cloud deployment or IoT (Internet of things). This feature first appeared in Ubuntu 16.04 LTS.

Using the Snappy Package Manager

Software bundles that can be packaged using the Snappy package manager are called snaps. Snaps can be installed using Ubuntu Software or from the command line, as described in this section.

To show a list of snap packages that are available to be installed, use the following:

matthew@seymour:~$ snap find

Because snaps are new, few packages are available today. However, the list is growing and is likely to become unwieldy at some point. Sure, you can use grep to search through the output to try to find a specific package in the list, but you can also use this:

matthew@seymour:~$ snap find searchterm

To install a snap package, use the following:

matthew@seymour:~$ sudo snap install packagename

To show a list of snap packages that are currently installed, use the following:

matthew@seymour:~$ snap list

To update a snap package, use the following:

matthew@seymour:~$ sudo snap refresh packagename

To remove a snap package, use the following:

matthew@seymour:~$ sudo snap remove packagename

To display a list of changes, such as when snaps were installed, updated, or removed, use the following:

matthew@seymour:~$ snap changes

References

www.debian.org/doc/manuals/project-history/ch-detailed.en.htmlHistory of the Debian Linux package system

www.nongnu.org/synaptic/Home of the Synaptic package manager

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.126.199