Ubuntu Package Management

dpkg

dpkg is a package manager for Debian based systems. It can install, remove, and build packages, but unlike other package management system's, it can not automatically download and install packages or their dependencies. This section covers using dpkg to manage locally installed packages:

  • To list all packages installed on the system, from a terminal prompt enter:

    dpkg -l 
  • Depending on the amount of packages on your system, this can generate a large amount of output. Pipe the output through grep to see if a specific package is installed:

    dpkg -l | grep apache2 

    Replace apache2 with any package name, part of a package name, or other regular expression.

  • To list the files installed by a package, in this case the ufw package, enter:

    dpkg -L ufw 
  • If you are not sure which package installed a file, dpkg -S may be able to tell you. For example:

    dpkg -S /etc/host.conf  base-files: /etc/host.conf 

    The output shows that the /etc/host.conf belongs to the base-files package.

    Many files are automatically generated during the package install process, and even though they are on the filesystem dpkg -S may not know which package they belong to.

  • You can install a local .deb file by entering:

    sudo dpkg -i zip_2.32-1_i386.deb 

    Change zip_2.32-1_i386.deb to the actual file name of the local .deb file.

  • Uninstalling a package can be accomplished by:

    sudo dpkg -r zip 

    Uninstalling packages using dpkg, in most cases, is NOT recommended. It is better to use a package manager that handles dependencies, to ensure that the system is in a consistent state. For example using dpkg -r you can remove the zip package, but any packages that depend on it will still be installed and may no longer function correctly.

For more dpkg options see the man page: man dpkg.

Apt-Get

The apt-get command is a powerful command-line tool used to work with Ubuntu's Advanced Packaging Tool (APT) performing such functions as installation of new software packages, upgrade of existing software packages, updating of the package list index, and even upgrading the entire Ubuntu system.

Being a simple command-line tool, apt-get has numerous advantages over other package management tools available in Ubuntu for server administrators. Some of these advantages include ease of use over simple terminal connections (SSH) and the ability to be used in system administration scripts, which can in turn be automated by the cron scheduling utility.

Some examples of popular uses for the apt-get utility:

  • Install a Package: Installation of packages using the apt-get tool is quite simple. For example, to install the network scanner nmap, type the following:

    sudo apt-get install nmap 
  • Remove a Package: Removal of a package or packages is also a straightforward and simple process. To remove the nmap package installed in the previous example, type the following:

    sudo apt-get remove nmap 

    Multiple Packages: You may specify multiple packages to be installed or removed, separated by spaces.

    Also, adding the --purge options to apt-get remove will remove the package configuration files as well. This may or may not be the desired effect so use with caution.

  • Update the Package Index: The APT package index is essentially a database of available packages from the repositories defined in the /etc/apt/sources.list file. To update the local package index with the latest changes made in repositories, type the following:

    sudo apt-get update 
  • Upgrade Packages: Over time, updated versions of packages currently installed on your computer may become available from the package repositories (for example security updates). To upgrade your system, first update your package index as outlined above, and then type:

    sudo apt-get upgrade 

    For information on upgrading to a new Ubuntu release see Upgrading.

Actions of the apt-get command, such as installation and removal of packages, are logged in the /var/log/dpkg.log log file.

For further information about the use of APT, read the comprehensive Debian APT User Manual or type:


Aptitude

Aptitude is a menu-driven, text-based front-end to the Advanced Packaging Tool (APT) system.

Automatic Updates

The unattended-upgrades package can be used to automatically install updated packages, and can be configured to update all packages or just install security updates. First, install the package by entering the following in a terminal:

sudo apt-get install unattended-upgrades 

To configure unattended-upgrades, edit /etc/apt/apt.conf.d/50unattended-upgrades and adjust the following to fit your needs:

Unattended-Upgrade::Allowed-Origins {
        "Ubuntu natty-security";
//      "Ubuntu natty-updates";
};

Certain packages can also be blacklisted and therefore will not be automatically updated. To blacklist a package, add it to the list:

Unattended-Upgrade::Package-Blacklist {
//      "vim";
//      "libc6";
//      "libc6-dev";
//      "libc6-i686";
};

The double “//” serve as comments, so whatever follows "//" will not be evaluated.

To enable automatic updates, edit /etc/apt/apt.conf.d/10periodic and set the appropriate apt configuration options:

APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Unattended-Upgrade "1";

The above configuration updates the package list, downloads, and installs available upgrades every day. The local download archive is cleaned every week.

You can read more about apt Periodic configuration options in the /etc/cron.daily/apt script header.

The results of unattended-upgrades will be logged to /var/log/unattended-upgrades.


你可能感兴趣的:(ubuntu,apt-get,dpkg,aptitude)