Wednesday, August 13, 2014

15 aptitude Command Examples for Package Management in Linux

This article explains several aptitude command examples including the following:
  • Install a specific version of a package
  • Install multiple packages using pattern
  • Search for a package using pattern
  • Get packages under a section
  • Don’t update a specific package (Using hold and keep)
  • Mark a package with a specific install type
  • Perform system update
  • Perform safe upgrade

1. Basic Package Install

Aptitude install is used to install packages along with its dependencies. For example, installing a package vim-gtk will also automatically install all the dependent packages.
# aptitude install vim-gtk
The following NEW packages will be installed:
libruby1.9.1{a} libyaml-0-2{a} tcl8.5{a} tcl8.5-lib{a} vim-gtk vim-gui-common{a} 
0 packages upgraded, 6 newly installed, 0 to remove and 317 not upgraded.
Need to get 6,360 kB of archives. After unpacking 19.0 MB will be used.
Do you want to continue? [Y/n/?] y
In the above output, aptitude will display the following:
  • List of all dependent packages that will be installed.
  • Total size of all the packages that will be downloaded, which is helpful to know how much data it will download from the repository.
  • Total disk size required after unpacking the packages.
  • At this stage, if you like to continue the installation, press “y”
Please note that you can also use apt-get command to manage packages as we discussed earlier.

2. Install Specific Version or Multiple Packages

It is also possible to install a particular version of a package as shown below. Specify the version number after the “=” sign.
# aptitude install "perl=5.10.1"
You can also install several packages matching a particular pattern as shown below.
# aptitude install ~nxvnc

3. View Package Information

Get information about a particular package as shown below.
# aptitude show vim-gtk
Package: vim-gtk     
State: not installed
Version: 2:7.3.547-6ubuntu5
Priority: extra
Section: universe/editors
Maintainer: Ubuntu Developers 
Architecture: amd64
Uncompressed Size: 2,442 k
Depends: vim-gui-common (= 2:7.3.547-6ubuntu5), vim-common (=
         2:7.3.547-6ubuntu5), vim-runtime (= 2:7.3.547-6ubuntu5), libacl1 (>=
         2.2.51-8), libc6 (>= 2.15), libgdk-pixbuf2.0-0 (>= 2.22.0),
         libglib2.0-0 (>= 2.12.0), libgpm2 (>= 1.20.4), libgtk2.0-0 (>= 2.24.0),
         libice6 (>= 1:1.0.0), liblua5.1-0, libpango1.0-0 (>= 1.14.0),
         libperl5.14 (>= 5.14.2), libpython2.7 (>= 2.7), libruby1.9.1 (>=
         1.9.2.0), libselinux1 (>= 1.32), libsm6, libtinfo5, libx11-6, libxt6,
         tcl8.5 (>= 8.5.0)
Suggests: cscope, vim-doc, ttf-dejavu, gnome-icon-theme
Conflicts: vim-gtk
Provides: editor, gvim, vim, vim-lua, vim-perl, vim-python, vim-ruby, vim-tcl
Description: Vi IMproved - enhanced vi editor - with GTK2 GUI
 Vim is an almost compatible version of the UNIX editor Vi. 
..

4. Search for a Package using a Pattern

To know the list of packages available in configured repository, use search option of aptitude along with the string pattern of the package name.
The following will display all the packages that has “xvnc” anywhere in the name.
# aptitude search xvnc
p   linuxvnc           - VNC server to allow remote access to a tty
p   linuxvnc:i386      - VNC server to allow remote access to a tty
p   xvnc4viewer        - Virtual network computing client software for X
p   xvnc4viewer:i386   - Virtual network computing client software for X

5. Display all Installed Packages

In order to list all the installed packages, use the search option as shown below:
# aptitude search '~i' | head
i   account-plugin-aim              - Messaging account plugin for AIM          
i   account-plugin-facebook         - GNOME Control Center account plugin for si
i   account-plugin-flickr           - GNOME Control Center account plugin for si
i   account-plugin-generic-oauth    - GNOME Control Center account plugin for si
i   account-plugin-google           - GNOME Control Center account plugin for si
i   account-plugin-jabber           - Messaging account plugin for Jabber/XMPP  
i   account-plugin-salut            - Messaging account plugin for Local XMPP (S
i   account-plugin-twitter          - GNOME Control Center account plugin for si
i   account-plugin-windows-live     - GNOME Control Center account plugin for si
i   account-plugin-yahoo            - Messaging account plugin for Yahoo!

6. Advanced Search for Packages

To display only broken packages on the system, do the following. This indicates that there are no broken packages on this system.
# aptitude search '~b' | head
To find partially uninstalled packages, do the following:
# aptitude search '~c'
c   yelp                  - Help browser for GNOME
To display held packages, do the following:
# aptitude search '~ahold'
ih  python3 - interactive high-level object-oriented language (default python3 version)
To search for the given keyword in the description, do the following. This example searches for the given text “vim” in descriptions of the packages.
# aptitude search '~dvim'

7. Packages under a Section

To list packages under a particular section, do the following. As seen below, there are 968 packages available under gnome package group.
# aptitude search '~sgnome' | wc -l
968
To display installed package under a section, do the following:
# aptitude search '~i~sgnome'| wc -l
142
As seen above, 142 packages are installed which belongs to gnome package group. You might also see uninstalled packages because of existence of their configuration files.

8. Uninstall a Package

To remove an installed package from a system as well as orphaned dependencies, use remove option along with exact installed package name as shown below:
# aptitude remove vim-gtk
The following packages will be REMOVED:  
  vim-gtk 
0 packages upgraded, 0 newly installed, 1 to remove and 317 not upgraded.
Need to get 0 B of archives. After unpacking 2,442 kB will be freed.
(Reading database ... 160189 files and directories currently installed.)
Removing vim-gtk ...
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vi (vi) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/view (view) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/ex (ex) in auto mode
update-alternatives: using /bin/nano to provide /usr/bin/editor (editor) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rvim (rvim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rview (rview) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vimdiff (vimdiff) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vim (vim) in auto mode

9. Complete Removal of a Package

Use purge option to perform a complete removal. This will uninstall a package as well as orphaned dependencies along with its configuration files
The following will uninstall postgresql package along with its configuration files.
# aptitude purge postgresql

10. Don’t Update a Package – Hold it

To keep the current version of the package, do the following:
# aptitude hold python3
As seen above, hold has been applied on python3 package. It cancels any future installations, removal and upgrade of this package. aptitude safe-upgrade or aptitude full-upgrade can not be done on this package.
The following is a way to hold a package along with install. Append “:” at the end of the package.
# aptitude install perl:
Use unhold to role back the hold applied on the package.

11. Don’t Update a Package – Keep it

To keep only the current version when there is a scheduled updates for packages, do the following:
# aptitude keep perl
keep-all option is to apply the same for all installed packages.

12. Mark a Package with Install Type

There is a provision to mark immediately after installing packages either as automatic or manual by override specifier as explained below.
To set the mark as automatic, do the following
# aptitude install package+M

(or)

# aptitude install package&M
To set the mark as manual, do the following. This is the default option.
# aptitude install package&m
It is mainly used when you want to get a list of manually installed packages. The following displays the automatically installed packages count.
# aptitude search '~M~i' | wc -l
130
The following displays the total count for manually installed packages.
# aptitude search '!~M~i' | wc -l
1556

13. Refresh Available Packages List

To update the list of available package from repositories, do the following:
# aptitude update

14. Upgrade All Packages – Safe and Full Upgrade

safe-upgrade: To upgrade the installed packages to the latest version and new packages might be installed to resolve dependencies, do the following:
# aptitude safe-upgrade
To prevent from installing new packages then use –no-new-installs as shown below:
# aptitude safe-upgrade --no-new-installs
full-upgrade: To do complete upgrade of all packages, and also to install packages which safe-upgrade cannot do, do the following:
# aptitude full-upgrade

15. Clean aptitude Cache

To remove downloaded packages from the cache directory, do the following. By default, the cache directory is /var/apt/apt/archive
# aptitude clean
Use autoclean to remove only the packages from cache which can no longer be downloaded.
# aptitude autoclean

No comments:

Post a Comment