Linux users are always keen to fire off terminal commands for new packages, but to begin with, how is anyone supposed to know the names of these packages? Once pointed out, it’s actually very simple. This tutorial will show you how to search for packages in the Terminal for both Ubuntu and Debian-based systems with apt and apt-get.
Ubuntu and Apt
In recent years, Ubuntu has simplified and enhanced some of Debian’s more unwieldy commands. The
apt-cache commands involved needless typing and were shortened to
apt, which performs the actions of both. To search for something in your repository, you just need to use apt with the word
search, followed by your search term. Say you wanted to look for golf games – you could search your repository simply by entering:
Apt will output a list of any relevant search results, searching through both package names and descriptions. With apt, package names will be highlighted in color to help differentiate them from other descriptive text.
In our golf search one of the available packages was kolf, so we’ll use that as our package for the following examples.
To install packages with apt, you simply replace search with install, followed by the name of your package. However, installing packages requires super user privileges, which on an Ubuntu system uses
sudo. The sudo command goes at the start of a terminal line, so on an Ubuntu system you would install kolf by entering:
Older Debian Systems
In place of the new and simplified apt command, older Debian releases use
apt-cache for searching. It still functions the same way as apt though. To search for golf once again, the command would be:
However, the information given is less extensive than with apt, as demonstrated in this screenshot.
Note that although Debian’s apt-get commands will work with Ubuntu, Ubuntu’s simplified apt commands may not work with Debian, depending on the age of your release. It’s worth trying the Ubuntu-style apt command first, as it comes with extra formatting and color coding.
If sudo is setup on your system, to install kolf you would enter:
However, on stock Debian your user may not be automatically added to the list of sudoers, meaning you’ll need to use root instead. This is easy though. If you’ve never used root before, just enter:
enter root password, and then enter your commands, minus the sudo part.
Notice the change from
$ to a
# – a root prompt. Don’t stick around in root for any longer than you need to, as this allows full system access, and you could damage something. Press Ctrl + D or type
exit to log out of root when you’re done.
Extending Your Usage
What if the information provided by apt search isn’t enough? What if you want to jump into much more detail? Once you know the name of your package, you can use apt show to tell you more information, including details such as the project’s website or whether or not there are any dependency conflicts. Sticking with kolf as an example, the command is:
Compare and contrast the output of kolf …
with the output for neverputt.
If you were choosing between the two packages, neverputt would be the package least likely to cause problems to your repository system.
For the older Debian equivalent, the command is:
A very common scenario: you’re using an old-fashioned terminal that doesn’t allow you to scroll back through a list of extensive text, leaving you stuck at the bottom. In this scenario, you can simply use a pipe (that’s the
| symbol) to send the output to a text reader like
less. To extend the kolf example in this way looks like this:
Now you can browse the output simply by using the arrow keys, and you can exit by pressing Q. You can use this pipe method for apt search as well, but be aware you will lose any of its fancy color coding on package names.
Now that you know how to search for packages in the terminal, are your packages getting messy? Does Ubuntu produce far too many error messages? Check out our guide on cleaning up Ubuntu.