Ubuntu has a lot of GUI-based methods for installing applications, but they take some time to search and find. Since the keyboard is usually faster than the mouse, managing your software via the command-line can be a real time-saver.

APT

Linux manages software through packages, individual units of software that contain user interfaces, modules, and libraries. Most applications link several co-dependent packages together, and still others allow you to choose which packages to install and which to leave out at your own discretion. This can get confusing, so there’s a package manager at your disposal to help

Each Linux distribution has its own package management system. For our own near and dear Ubuntu, it’s the Advanced Packaging Tool. It has a family of commands that allows you to add repositories; search for, install, and remove packages; and even simulate upgrades and such. The commands are fairly easy to remember and use, so you’ll be managing your system’s software in no time at all!

APT requires super-user permissions, as it deals with core aspects of the system, so in Ubuntu you’ll need to preface most commands with “sudo.”

Searching for Packages

The command to search for software is:

Replace [search terms] but don’t use brackets. You’ll get an output like this:

You can search for terms in the description of packages, say for a solitaire game, or by package name. Some searches may yield a ton of results, so you can scroll through the list with the following command:

There’s a pipe in the middle of that command (it shares a key with ). The less command will allow you to scroll through your list with the arrow keys, page up/down keys, and space, b, and enter. Hit q to exit the list and go back to the prompt.

Adding Repositories

You can find more software in repositories found online. Take, for instance, Ubuntu Tweak, a program that lets you change some hidden or otherwise difficult-to-change settings for your system. It’s hosted at another repository. If you add the repository instead of downloading and installing just the package, the system will notify you of updates and automatically keep it up-to-date for you. You can manually add and change repositories by editing APT’s sources file:

But Ubuntu 9.10 Karmic Koala changed that. There’s an easier way!

Let’s look at Ubuntu Tweak’s repo to see what it’ll look like in practice:

Voila!

Updating Sources

After adding repositories, you have to update your package list.

That will update the package lists from all repositories in one go. Remember to do this after every added repository!

Installation

Now that you’ve added your software repo and updated your package list, and found the package name you need, you can install it.

This will download and install all of the packages listed. If there are dependencies – other prerequisite packages – they will also be installed. Sometimes you’ll also see a list of recommended but optional packages to go along with your selection. Sometimes, you’ll also see a confirmation prompt, though not always.

Often, you’ll see a core package with other linked packages, so installing this one will automatically install the dependencies and sometimes its associated packages, too.

Removing Packages

If you want to get rid of a program, you can uninstall its associated packages.

If you want to get rid of the configuration files and associated directories (usually in the user’s home directory), you’ll want to add the purge option:

There are two dashes there. This will come in handy if a program isn’t working properly. By purging upon removal, you’ll can have a “clean” install.

Most of the time, you can just choose the core package and the associated ones will be removed as well. If it doesn’t, you can use the following command:

This will automatically remove any packages that aren’t used or associated with any installed program. For example, if you got rid of a core package, autoremove will get rid of it’s associated packages and any dependencies it had, so long as no other program is using them. It’s a great way to clean up any unused libraries and packages you don’t need.

Upgrading Software

So, what if your packages need upgrading? You can upgrade individual programs with the following command:

Or, you can upgrade all packages by having no further arguments:

This will tell you how many and which packages need updating and will ask for a confirmation before it continues.

Remember, you may need to update first. Upgrade will replace older versions of programs with their newer versions. This is a replacement process; the same package name is required and the older version is replaced with a newer version. No completely new packages are installed and no packages are uninstalled.

Some programs don’t quite work that way. They require a package with a slightly different name to be removed and a new one with a different name to be installed. Sometimes a program’s new version has a new required package. In these cases, you’ll need to use dist-upgrade.

Now, all of the dependencies will be satisfied no matter what. If you aren’t into micro-managing your packages, then this is the command you’re going to use.

sudo apt-get dist-upgrade

If you only want to see which packages will be upgraded if you were to hypothetically run the command, you can simulate an upgrade with the –s option.

This is really useful if you aren’t sure if upgrading one package will mess up other programs, which happens occasionally with things like PHP and mail server libraries.

Cleaning

When you download packages, Ubuntu caches them in case it needs to refer to them further. You can delete this cache and get back some hard drive space with the following command:

If you want to get rid of your cache, but save the newest versions of what packages you have, then use this instead:

This will get rid of the older versions which are pretty much useless, but still leave you with a cache.

Checking What’s Installed

You can see a list of all your installed packages with dpkg.

You can also use less to scroll through this list.

You can also search through the list with the grep command.

If something is installed, you’ll see a package name and a description.

You can also search through a more compact method:

That option is a lowercase letter L, and your search term must be inside single quotes. You can use wildcard characters to search better as well.

Easter Egg

APT has an interesting easter egg.

Enjoy your super cow powers!

Being able to manage packages and installed software via command-line can save you some time. Ubuntu’s Software Updater is often laggy on my system and it can really be a pain to have to add software repos and install packages through the Software Center, especially if you know the package names already. It’s also great for managing your system remotely via SSH. You don’t need to have a GUI running at all or deal with VNC.

There are a lot of things to learn when getting comfortable with the command-line, so you may want to check out The Beginner’s Guide to Nano, the Linux Command-Line Text Editor. There’s more to come!