Guide to using apt-get


apt-get is the command-line tool for handling packages, and may be considered the user’s “back-end” to other tools using the APT library. APT is actually both a library and a front-end for dpkg to work with Debian’s .deb packages. It’s designed to track package dependencies, call dpkg and make the software installation easy.
Note: This entry is written with Ubuntu users in mind, hence the use of sudo when root access is required.

Package installation

Install a new package like follows:
sudo apt-get install foobar
You can also install multiple packages with one line, just separate the package names with a space:
sudo apt-get install foobar1 foobar2 foobar3
All required dependencies by the package(s) specified for installation will also be retrieved and installed.

Search

(OK, so you don’t use apt-get for searching, but apt-cache. Still comes in pretty handy though.) When you can’t remember the correct package name then you can search package names and descriptions using
apt-cache search foobar
Or, for a fuzzy search try
apt-cache search foo
This can result in a long list, every package that includes ‘foo’ anywhere in its name or description will be listed. To narrow it down to package names, or packages with words in their descriptions, which start with ‘foo’ try
apt-cache search ^foo
For names/words that end with ‘foo’ try
apt-cache search foo$

Installation from source

Instead of APT fetching the pre-built .deb for a package you can also use APT to build the package from its source code and get an optimised version for your system. Generally debs are absolutely fine to install, but you could see performance increases with CPU intensive packages (e.g. ffmpeg).
sudo apt-get build-dep foobar
sudo apt-get -b source foobar
The first line causes apt-get to install/remove packages in an attempt to satisfy the build dependencies for the package foobar. The second line fetches the source package for foobar. It finds and downloads the newest available version of that source package into the current directory. Source packages are tracked separately from binary packages via deb-src type lines in the /etc/apt/sources.list file. This probably will mean that you will not get the same source as the package you have installed or as you could install. With the -b option specified the package will be compiled to a binary .deb using dpkg-buildpackage. Depending on the package this can take a long time.
Once built, install the package with
sudo dpkg -i foobar-version-number.deb

Package removal and clean-up

To remove a package use
sudo apt-get remove foobar
The software package will be removed, but all of its configuration files will be left behind. This could come in handy if you ever plan on re-installing the package, everything will be back to the way it was before the uninstall.
To remove a package complete with its configuration files use
sudo apt-get --purge remove foobar
What happens to dependencies that were installed with the package? They are left behind. To clean these up use
sudo apt-get autoremove
autoremove removes packages that were automatically installed to satisfy dependencies for some package and that are no longer needed. If you have been trying out a lot of software then this might free up some disk space.
sudo apt-get autoclean
autoclean clears out the local repository (/var/cache/apt/archives/ and/var/cache/apt/archives/partial/) of retrieved package files that can no longer be downloaded and are largely useless. This allows a cache to be maintained over a long period without it growing out of control.
sudo apt-get clean
clean is more thorough than autoclean. It removes everything but the lock file from/var/cache/apt/archives/ and /var/cache/apt/archives/partial/. You will likely want to run apt-get clean from time to time to free up disk space.

Upgrade

There are two ways to upgrade your system. First a software update:
sudo apt-get update
sudo apt-get upgrade
This installs the newest versions of all packages currently installed on the system. Packages currently installed with new versions available are retrieved and upgraded; under no circumstances are currently installed packages removed, or packages not already installed retrieved and installed. New versions of currently installed packages that cannot be upgraded without changing the install status of another package will be left at their current version. An update must be performed first so that apt-get knows that new versions of packages are available.
Second, a distro upgrade:
sudo apt-get update
sudo apt-get dist-upgrade
dist-upgrade in addition to performing the function of upgrade, also intelligently handles changing dependencies with new versions of packages; apt-get has a “smart” conflict resolution system, and it will attempt to upgrade the most important packages at the expense of less important ones if necessary. The /etc/apt/sources.list file contains a list of locations from which to retrieve desired package files.

1 comment:

  1. wow...
    thank you...
    hope u can give more tutorial like this...

    ReplyDelete

Find Us On Facebook

Related Posts Plugin for WordPress, Blogger... Linux Directory