Living Without Synaptic


Despite its quirks, Synaptic is a very useful utility for keeping up-to-date on patches and installing new software. Unfortunately, Synaptic requires human interaction and a graphical interface. If you installed the Ubuntu server or are remotely logged into the system, then you probably do not have the graphical interface. And when managing dozens (or hundreds) of systems, depending on a graphical interface becomes an impediment.

Fortunately, Synaptic is a graphical front end to the Advanced Package Tool environment; every basic Synaptic function comes from APT. Using the APT commands, you can search for software, install packages, and perform upgrades from the command line.

Modifying Sources

APT uses a configuration file to tell it where repositories are located. The file /etc/apt/ sources.list contains a list of servers, distributions, and repositories. Listing 4-1 shows some sample repositories. If you want to add or change repositories, simply edit the file (as root) and make your additions or modifications. There is no need to restart any services or processes.

Note 

The /etc/apt/sources.list file is used by dpkg, APT, and Synaptic. Technically, APT is a wrapper around dpkg, and Synaptic is a graphical front-end to APT. Changes to this file affect all of these tools.

Each line within this file contains four key elements:

  • Type of data-The available data is either precompiled binaries (deb) or source code for compiling binaries (deb-src).

  • Location-A URL says how to get the data. This is usually an HTTP, HTTPS, or FTP server, but it can also be a local CD-ROM or a directory.

  • Distribution-The name of the distribution is provided. Example names include dapper, dapper-updates, and dapper-security.

  • Component-One or more components are specified, such as main, restricted, universe, or multiverse.

image from book
When All Else Fails

Knowing how Synaptic works under the hood, and how to use APT from the command line can be critical for system recovery. On August 21, 2006, the maintainers of Ubuntu accidentally released a bad update. This update disabled X-Windows, leaving users at a command line prompt. Graphical tools, such as Synaptic, suddenly became unavailable. The only mitigation option was to use apt-get to reinstall the X-server from the command line after Ubuntu fixed the error in the X-Windows packages.

Not all failures are due to bad updates. On Saturday, July 22, 2006, many of the servers hosting Ubuntu repositories went offline-and some stayed offline the entire weekend. Refreshing the Synaptic repository list generated a cryptic error message (and sometimes crashed Synaptic). Knowing how to manually change the servers from one region to another was the only way to apply patches and install essential software. And changing the servers is a task easier done without using Synaptic. (The downtime was later attributed to a series of server upgrades.)

Accidents happen, but without knowing how to identify errors or recover from them, you can end up with an unusable system. The command line apt-get and apt-cache tools generate informative errors that can be used to diagnose these problems. In the case of a bad server or network connection, editing the /etc/ apt/sources.list file can provide a quick solution.

image from book

Listing 4-1: Sample Entries from an /etc/apt/source.list

image from book
 # The server "uk.archive.ubuntu.com" contains source code for the "dapper" # distribution. The distribution contains "main" and "restricted" repositories. deb-src http://uk.archive.ubuntu.com/ubuntu/ dapper main restricted # The same server contains binary for the updates distribution. deb http://uk.archive.ubuntu.com/ubuntu/ dapper-updates main restricted # The CD-ROM with label "Ubuntu 6.06 _Dapper Drake_ - Release i386 (20060531)" # also contains dapper main. deb cdrom:[Ubuntu 6.06 _Dapper Drake_ - Release i386 (20060531)]/ dapper main # A local directory -- this can be a mounted directory such as a CD-ROM or a # networked file system (NFS) deb file:/mnt/iso dapper main # My full list of sources deb http://us.archive.ubuntu.com/ubuntu/ dapper main restricted deb-src http://us.archive.ubuntu.com/ubuntu/ dapper main restricted deb http://us.archive.ubuntu.com/ubuntu/ dapper-updates main restricted deb-src http://us.archive.ubuntu.com/ubuntu/ dapper-updates main restricted deb http://security.ubuntu.com/ubuntu dapper-security main restricted deb-src http://security.ubuntu.com/ubuntu dapper-security main restricted deb http://security.ubuntu.com/ubuntu dapper-security universe deb-src http://security.ubuntu.com/ubuntu dapper-security universe 
image from book

Tip 

If you want to exclude a specific repository, then make sure the /etc/apt/sources.list file does not include it on any of the repository lines. For example, to exclude multiverse, make sure all multiverse lines are commented out (with a # character) or removed from the uncommented line.

After you make any changes to /etc/apt/sources.list, you will need to refresh the APT cache of available packages: sudo apt-get update. This updates the cache of available software. Without this command, you won't search the list of available software. When you enable the automatic check for patches, the system actually runs the apt-get update command.

Note 

If you make changes to /etc/apt/sources.list and you use Synaptic, then you can click the Reload button to refresh the cache. Otherwise you need to run sudo apt-get update.

The list of servers should match your region. For example, us.archive.ubuntu.com is intended for users in the United States. The uk.archive.ubuntu.com server is for the United Kingdom, and ca.archive.ubuntu.com supports Canada. A few two-character country codes (for example, uk and us) are currently defined; undefined country codes are redirected to the United Kingdom because that is where Canonical is located. If you find that a particular region is temporarily unavailable, then try changing regions by modifying each of the server's names in /etc/apt/source.list. It is rare for all of the servers to be unavailable at the same time.

Adding CD-ROM Repositories

Besides using Synaptic, there are two ways to add a CD-ROM to /etc/apt/source.list. The first way requires you to manually identify the CD-ROM label and then add it. The apt- cdrom command can list the disk's label. Let's assume that the Ubuntu installation CD-ROM is mounted at /mnt/iso:

 $ apt-cdrom -m -d /mnt/iso ident Using CD-ROM mount point /mnt/iso/ Mounting CD-ROM Identifying.. [d9f91a1075ce140463bf88837cc07be6-2] Stored label: Ubuntu 6.06 _Dapper Drake_ - Release i386 (20060531) 

Tip 

The -m parameter for apt-cdrom says to not mount the disk, otherwise the CD-ROM sitting in the drive will be used. The -d parameter specifies the mount point for acquiring the label and ident directs the command to identify the CD-ROM label.

After finding the CD-ROM name, you can add it to the /etc/apt/sources.list file with a cdrom: resource. For example, to install the main component, I would use:

 deb cdrom:[Ubuntu 6.06 _Dapper Drake_ - Release i386 (20060531)]/ dapper main 

Although you can add a disk manually, the easiest way to add a CD-ROM is to let apt-cdrom do it.

  1. Insert the CD-ROM into the drive.

  2. Run the command.

     sudo apt-cdrom add 

The CD-ROM is automatically added to the /etc/apt/source.list file.

Note 

After adding a CD-ROM to the /etc/apt/sources.list file, be sure to run apt-get update. This adds the packages on the CD-ROM to the cache of known packages.

Browsing the APT Cache

Another command, apt-cache, enables you to search the repositories for a particular subject or file name. The search word will match any package's name or description. For example, if you are searching for a calculator, you could use:

 $ apt-cache search calculator bc - The GNU bc arbitrary precision calculator language gcalctool - A GTK2 desktop calculator dc - The GNU dc arbitrary precision reverse-polish calculator bison - A parser generator that is compatible with YACC 

Tip 

Searches are case-insensitive and look for sub-strings. You can search for multiple words in sequence using quotes like apt-cache search "gnu bc". You can also list multiple terms (without quotes) that will be matched in any order. For example: apt-cache search calculator calctool.

It may seem odd that Bison (Yet Another Compiler-Compiler) is listed as a calculator, but another apt-cache command shows the entire package's description and lets us understand why it was listed. (Bison's description contains the word calculator.)

 $ apt-cache show bison Package: bison Status: install ok installed Priority: standard Section: devel Installed-Size: 1264 Maintainer: Chuan-kai Lin <cklin@debian.org> Architecture: i386 Version: 1:2.1-0.2ubuntu1 Depends: m4, libc6 (>= 2.3.4-1) Recommends: bison-doc Description: A parser generator that is compatible with YACC  Bison is a general-purpose parser generator that converts a  grammar description for an LALR(1) context-free grammar into a C  program to parse that grammar. Once you are proficient with Bison, you  may use it to develop a wide range of language parsers, from those used  in simple desk calculators to complex programming languages. ... 

Other options for apt-cache can show dependencies, requirements, and contents. The man page for apt-cache details other options (man apt-cache).

Organizing Search Results

The results from apt-get search are not sorted by package name. Instead, they are sorted by server repository. In the case of the calculator search, bison is listed after dc because it came from a different repository. If you want the results sorted by package name, then you will need to sort them yourself:

 apt-cache search calculator | sort 

Similarly, if you are searching for a specific package name or description, then you will need to apply a filter:

 apt-cache search calculator | grep gcalctool 
Tip 

You can use grep to restrict results to the displayed text. This is different than using multiple terms with apt-cache search since the matched results may not be in the displayed text.

Installing with APT

After you know what to install, you can use the apt-get install command to perform the installation. You can list one or more packages after the install instruction. If you want to see what will happen without actually doing the install, use the -s option to simulate the installation. You will see every warning and message without actually doing the install.

 sudo apt-get -s install gcalctool   # check the install sudo apt-get install gcalctool      # perform the install 

Although the gcalctool application is installed by default, when you install the Ubuntu desktop, its source code is not. Source code is available for all packages in main and universe. However, source may not be available for packages found in restricted or multiverse.

Tip 

While Synaptic gives cryptic error messages (or crashes) when /etc/apt/sources.list contains bad entries or is misconfigured, the apt-cache and apt-get commands will display plenty of errors and warnings.

Removing Packages with APT

Package removal is nearly as painless as installation.

  1. First, find the package name you want to remove. You can use apt-cache search or apt-cache pkgnames to list all packages, but the easiest way is to use dpkg.

     dpkg -l | more 

    Alternately, if you know a file that is in the package, then you can use dpkg -S to list all packages containing that file. For example, to remove whatever package provides the program bc, you can use:

     dpkg -S `which bc` 
  2. Use apt-get to check what will be removed. Some package dependencies will force the removal of other packages. For example, to check the removal of the bc package, use:

     sudo apt-get -s remove bc 
  3. If the removal looks safe, then use apt-get to remove the package. For example, to remove the bc package, use:

     sudo apt-get remove bc 
Warning 

The bc package is installed as part of the default desktop. Removing bc removes a dependency from a trivial package called ubuntu-desktop. This isn't the actual desktop, but it is used as a flag to indicate that the full desktop is installed. To see everything in the ubuntu-desktop package, use dpkg -L ubuntu-desktop.

Removing Residues

Most software removals are clean-everything that went in is taken out. Unfortunately, some removals leave residues, such as configuration and data files. Removing or reinstalling a package because it is misconfigured may not replace critical configuration files. This can result in the package remaining misconfigured after being installed. A few examples:

  • Removing and reinstalling a Web browser will not clear user-caches or replace user settings. This is not a solution for fixing privacy issues from cached Web pages.

  • Removing and reinstalling Gnome will not remove $HOME/.gnome, $HOME/.gnome2, and other Gnome-related files in user directories.

  • Many packages check for modified configuration files. If you modify a configuration file, such as /etc/X11/xorg.conf or /etc/gdm/gdm.conf, then it may not be removed when these packages are removed.

Note 

If you are reinstalling software because of a configuration problem, be aware that this may not fix the problem.

Leftover files and other residues may need to be manually cleaned up (or deleted) before you decide to reinstall the package. In the case of a misconfiguration, reinstalling the system usually will not resolve problems-especially if the configuration problem is due to files stored in a user's directory or created after the installation.

Tracking Removals

As mentioned earlier, one of the biggest problems with removals comes from dependent packages. Removing one package may automatically select other packages and remove them too. Although using apt-get -s remove can be useful, always remember to use the -s to check first. If you forget the -s then you will need some way to see everything that was removed (so you can put back critical packages). Fortunately, you have two options (besides restoring from a system backup). First, the /var/log/dpkg.log file contains a list of every addition and removal (see Listing 4-2). This log file is updated every time Synaptic, ATP, or dpkg installs or removes packages. Using this list, you can see what was removed and undo an accidental removal.

Listing 4-2: Sample Contents from /var/log/dpkg.log

image from book
 2006-08-25 18:37:17 install dpkg-dev <none> 1.13.11ubuntu6 2006-08-25 18:37:17 status half-installed dpkg-dev 1.13.11ubuntu6 2006-08-25 18:37:18 status unpacked dpkg-dev 1.13.11ubuntu6 2006-08-25 18:37:18 status unpacked dpkg-dev 1.13.11ubuntu6 2006-08-25 18:37:18 status unpacked dpkg-dev 1.13.11ubuntu6 2006-08-25 18:37:18 status unpacked dpkg-dev 1.13.11ubuntu6 2006-08-25 18:37:18 status unpacked dpkg-dev 1.13.11ubuntu6 2006-08-25 18:37:18 status half-configured dpkg-dev 1.13.11ubuntu6 2006-08-25 18:37:18 status installed dpkg-dev 1.13.11ubuntu6 2006-08-26 08:06:01 status installed dpkg-dev 1.13.11ubuntu6 2006-08-26 08:06:02 remove dpkg-dev 1.13.11ubuntu6 1.13.11ubuntu6 2006-08-26 08:06:02 status half-configured dpkg-dev 1.13.11ubuntu6 2006-08-26 08:06:02 status half-installed dpkg-dev 1.13.11ubuntu6 2006-08-26 08:06:02 status config-files dpkg-dev 1.13.11ubuntu6 
image from book

The second option is to use the script command. This command logs all command line output to a file:

 $ script -c "sudo apt-get remove dpkg-dev" apt-get.log Script started, file is apt-get.log Reading package lists... Done Building dependency tree... Done The following packages will be REMOVED:   dpkg-dev 0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded. Need to get 0B of archives. After unpacking 541kB disk space will be freed. Do you want to continue [Y/n]? y (Reading database ... 106427 files and directories currently installed.) Removing dpkg-dev ... Script done, file is apt-get.log 

From the script command, you will get a file called apt-get.log containing the entire removal session. This command can even be turned into a simple script that you can use instead of using the actual apt-get command (see Listing 4-3).

Listing 4-3: Replacement /usr/local/bin/apt-get for Logging Results

image from book
 #!/bin/sh # Run the apt-get command and append (-a) results to ./apt-get.log script -a -c "sudo /usr/bin/apt-get $*" apt-get.log 
image from book

Upgrading with APT

Applying upgrades is a two-step process. First, use apt-get update to retrieve the list of available software packages and upgrades based on your /etc/apt/sources.list. If there are any updates, then the update indicator will appear on the top panel. After getting the list of updates, use apt-get upgrade to perform the upgrade.

 $ sudo apt-get update Get:1 http://archive.ubuntu.com dapper Release.gpg [189B] Get:2 http://archive.ubuntu.com dapper Release [34.8kB] Get:3 http://archive.ubuntu.com dapper/universe Packages [2458kB] Hit http://us.archive.ubuntu.com dapper Release Hit http://us.archive.ubuntu.com dapper-updates Release Hit http://us.archive.ubuntu.com dapper/main Sources ... Fetched 3117kB in 7s (416kB/s) Reading package lists... Done $ sudo apt-get upgrade 



Hacking Ubuntu
Hacking Ubuntu: Serious Hacks Mods and Customizations (ExtremeTech)
ISBN: 047010872X
EAN: 2147483647
Year: 2004
Pages: 124
Authors: Neal Krawetz

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net