How-To Geek

How to Install Programs in Ubuntu in the Command-Line


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.


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:

apt-cache search [search term 1] [search term 2] … [search term n]

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:

apt-cache search [search terms] | less

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:

sudo nano /etc/apt/sources.list

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

add repo

sudo add-apt-repository [repository name here]

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

sudo add-apt-repository ppa:tualatrix/ppa


Updating Sources


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

sudo apt-get update

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


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

sudo apt-get install [package name 1] [package name 2] … [package name n]


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.

associated packages-mod

Removing Packages

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

sudo apt-get remove [package name 1] [package name 2] … [package name n]


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:

sudo apt-get remove –purge [package name 1] [package name 2] … [package name n]

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:

sudo apt-get autoremove

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:

sudo apt-get upgrade [package name 1] [package name 2] … [package name n]

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

sudo apt-get upgrade

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.


sudo apt-get dist-upgrade [package name 1] [package name 2] … [package name n]

sudo apt-get 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.

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.

sudo apt-get –s upgrade

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.


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:

sudo apt-get clean

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

sudo apt-get autoclean

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.

sudo dpkg –list

You can also use less to scroll through this list.

sudo dpkg –list | less

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

dpkg –list | grep [search term]

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

You can also search through a more compact method:

dpkg –l ‘search term’

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.

dpkg search

Easter Egg

APT has an interesting easter egg.

sudo apt-get moo

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!

Yatri Trivedi is a monk-like geek. When he's not overdosing on meditation and geek news of all kinds, he's hacking and tweaking something, often while mumbling in 4 or 5 other languages.

  • Published 05/19/11

Comments (20)

  1. Anish Sane

    is there any provision to use fastest mirror for downloading deb packages?

    for RPM based linuxes, there is a package called fastest-mirror, which periodically checks if some server is down & checks which is the fastest mirror for downloading the packages.

  2. cgtdk

    aptitude > apt-get

  3. Anon

    What I liked about sudo apt-get install application-name is, it is simple and fast, way better than that app center UI they came out with. Some cool watching the terminal compile software as well when needed.

  4. Leonel

    I tried both apt-get and aptitude and I find aptitude better than apt-get. Well, aptitude is a command line front of apt-get as synaptic is the gui front end of apt-get. With aptitude, uninstalling a package also uninstalls the dependencies while apt-get doesn’t (or seldom). That’s exactly the reason why there is autoremove option in apt-get.

  5. durr

    “apt-cache search” is the ugliest packagemanagement search evar

  6. michel

    Buy a Windows machine. Click, click, installed.

  7. warren krause

    Gdebi package installer is a must have for installing ease also. Some distro’s you have to get it from software or Synaptic. Fast and gives you info on dependency requirements. And tells why you can’t install, if.

  8. dave

    I really think Ubuntu is great, especially for Windows users looking to jump ship. But it isn’t the only Linux distro out there. Why not have some articles on SuSE or Fedora?

  9. durr

    Why not have some articles on SuSE or Fedora?
    Because RPM/Yast sucks

  10. mark

    Yast is pretty bad, especially compared to apt-get

  11. Lius

    i like aptitude instead apt-get

  12. Dave Lowe

    Ubuntu is a double edged sword. It’s expanded the Linux user base, but in the process has “dumbed down” Linux. It’s the AOL of distributions. But Ubuntu has many variants for experimentation, Kubuntu, Xubuntu, Edubuntu, Mythbuntu, and prettu much any *buntu you can imagine. And it makes an awesome “gateway drug” for the hardcore users out there to get started with Linux.

    Far cry from when I started in 1997. Red. Hat. Four.

    These days, I am a devout Debianista, I use “CrunchBang Linux” as my main distro, and XBMC Live (an *buntu joint!) on my media centers.

  13. Chris

    No apropos? :(

  14. KTown

    How is typing all these commands faster than the Ubuntu Software Center?

  15. ABC

    Aptitude is much better in dependency management than apt-get.
    Stop the apt-get propaganda.

  16. Jim

    no mention of the ability to install .deb packages from the web w/ a CLI…also you can download them if you know the propper address/usage of wget from online then a simple && followed by the .deb command will have your .deb software installed way faster than w/ software ctr. constantly throwin something or other in your face…just sayin…

  17. Fernando Melo Medeiros

    I have already tried Ubuntu and other Linux distributions, I mean I have always installed one of them with Windows 98 ( oh, how I miss this one, it was so easy and comfortable to work with it! ), Millennium, XP and Windows 7. I had Slackware with my XP, and Slackware with my Win 7. I have just uninstalled Slackware, because in spite of the fact that I have tried hard to use it as easily as I use any of the above mentioned Windows, I could never do so unfortunately. And I have been trying this not only for some months but for ten years. I tried all those distros hoping that suddenly I could have the right one but I never was that lucky. I don’t need Linux but I like that command line thing. I hope someday I can know how to use Linux. Not even to play a simple MIDI sequence, I never could do.

  18. Eitan

    Thats sudo apt-get update
    not sudo apt-get upgrade

  19. Eitan

    Never mind my last comment I didn’t look at the right place.

  20. cree

    i need to know step by step how to down load adobe reader ican not read all my e-mails with out it and need it really bad

Enter Your Email Here to Get Access for Free:

Go check your email!