How to Search for Packages in the Terminal with Apt and Apt-Get

Rispondi
Avatar utente
openresource
Administrator
Administrator
Messaggi: 382
Iscritto il: mar gen 28, 2020 9:52 pm
Reactions score: 4
Località: varese
Contatta:
giu 2020 18 05:53

How to Search for Packages in the Terminal with Apt and Apt-Get

Messaggio da openresource

Immagine

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-get and 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:

Codice: Seleziona tutto

apt search golf

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.

Immagine

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:

Codice: Seleziona tutto

sudo apt install kolf

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:

Codice: Seleziona tutto

apt-cache search golf

Immagine

However, the information given is less extensive than with apt, as demonstrated in this screenshot.

Immagine

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:

Codice: Seleziona tutto

sudo apt-get install kolf

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:

Codice: Seleziona tutto

su

enter root password, and then enter your commands, minus the sudo part.

Codice: Seleziona tutto

# apt-get install kolf

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:

Codice: Seleziona tutto

apt show kolf

Compare and contrast the output of kolf …

Immagine

with the output for neverputt.

Immagine

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:

Codice: Seleziona tutto

apt-cache show kolf

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:

apt show kolf | less
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.

Immagine

Immagine
Rispondi