Ubuntu is widely regarded as a beginner friendly version of Linux, but that doesn't mean that Ubuntu is only used by beginners. Advanced users can also make use of some of the great features Ubuntu has to offer.

If you have used Ubuntu for any length of time, it's likely that you will have had to use an apt-get command at some point. But did you know there's so much more to APT than apt-get update and apt-get upgrade?

What Is APT?

APT stands for Advanced Package Tool, the clue is in the name -- it's a command line tool for managing packages within Ubuntu.

Ubuntu is based on another distribution, called Debian. Debian uses it's own package manager, DPKG, and APT builds upon DPKG to make it more user-friendly.

You can install, update and clean packages with APT, as well as find new packages to install. The packages you can find are dependent on which PPAs you have enabled on your machine.

Managing Packages With apt-get

You can use the apt-get command to install, update and clean the packages that are available to your system. APT uses a local database of packages, which tells the system if any updates are available.

Keeping this database up to date is extremely important, as using out of date packages can lead to security issues on your machine. To update the APT database, you can use the following command:

        sudo apt-get update
    
apt-get-update

There are three types of update to the APT database:

  • Hit -- This means there is no change to the package since the last check.
  • Ign -- This means the package has been ignored, either because the package is so recent that there's no need to check it, or because there is a small error. Either way, this is nothing to worry about.
  • Get -- This means there is a package update available and APT will now download the details for this update, but not the update itself.

Once you have updated your database, you can use APT to then update the packages on your system. This will update any applications, and the Ubuntu core system to the latest versions available.

        sudo apt-get upgrade
    
apt-get-upgrade

Upgrade a Specific Package

Sometimes you may wish to upgrade a specific package, rather than the whole system. APT allows you to do this with the following command:

        sudo apt-get upgrade [package-name]
    

This will then update that specific package. This can be useful if there is a known bug with a certain package, yet you want to still upgrade others.

Dist-Upgrade

APT also has a slightly more intelligent way of upgrading your packages, this tool is known as dist-upgrade. It is used in the same way as the standard upgrade command:

        sudo apt-get dist-upgrade
    

In addition to performing the function of upgrade, dist-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. So the dist-upgrade command may remove some packages.

Because dist-upgrade can remove packages as well as update them, it is generally recommended that this command isn't used unless absolutely necessary, or when doing an update to the latest version of Ubuntu.

Remember to always run a backup prior to any dist-upgrade.

Combining Commands

It's very important to run an update before an upgrade when using APT, but some people may find running multiple commands frustrating. However, you can combine commands in Ubuntu so that one command can run two functions.

To carry out an update followed by an upgrade, you can run this command:

        sudo apt-get update -y && sudo apt-get upgrade -y
    
apt-get-update-and-upgrade

This command is basically telling APT to run an update and say yes to any prompts, then run an upgrade and again, say yes to any prompts. This will completely automate the update and upgrade process.

Searching for Packages

APT is also very useful for finding new packages. Although there are better ways of searching for new packages in Ubuntu, the apt-cache command does come in handy when looking for a specific lib or package.

To search for a package using APT you can use the following command:

        apt-cache search [search term]
    
apt-cache-search

As you can see from the output above, the search feature is fairly verbose and will allow you to search for terms, rather than package names, so you don't have to know the name of the package you're searching for.

However, if you want to search for packages that contain your search term within their name, you can use the following command:

        apt-cache pkgnames [search term]
    
apt-cache-pkgnames-search

Once you know the name of the package you are looking for, you can then use the following command to get more information about that package:

        apt-cache showpkg [package name]
    
apt-cache-showpkg

Once run, this command will show information such as version numbers and dependencies. This information can be very useful when it comes to installing new packages.

Install/Remove Packages With APT

Like sudo apt-get update, the install command from APT is probably one that you have come across before when installing new applications with Ubuntu and APT.

The command to install a package using APT is:

        sudo apt-get install [package name]
    

Conversely, to remove a package using APT, you simply replace the word "install" with "remove":

        sudo apt-get remove [package name]
    
apt-get-install

More to Learn

This guide merely touches the surface of what you can do with APT. It's an extremely powerful tool that is at the core of Ubuntu, as well as many other distributions.

If you want to continue to learn about APT, you can have a flick through the APT man pages using the following command:

        man apt
    
man-apt

Are you a terminal user, or do prefer to stick with the Ubuntu Software Center? Feel free to share your tips in the comments below.