LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Ubuntu (http://www.linuxquestions.org/questions/ubuntu-63/)
-   -   list packages (http://www.linuxquestions.org/questions/ubuntu-63/list-packages-746200/)

doru 08-09-2009 08:50 AM

list packages
 
I am new at Ubuntu and learning to use apt. It seems that packages are marked in a number of ways, and I can't follow this easily. Can anyone please clarify what do these commands actually list:

Code:

dpkg --get-selections | wc -l
318
dpkg -l | wc -l
323
dpkg -l \* | wc -l
852
apt-cache search . | wc -l
25211
apt-cache pkgnames | wc -l
32633

dpkg -l lists 5 header lines, so it corresponds to dpkg --get-selections, both list installed packages.
dpkg -l \* also lists some not installed packages, but less than apt-cache search ..
apt-cache search . lists all installed and available packages?
apt-cache pkgnames apparently includes older versions packages in its list.

Also, please tell me if apt-get is functionally equivalent to aptitude? I mean, anything done easily in command line with aptitude can also be done easily with apt-get and its apt-* companions?

Thank you for your time.

tommcd 08-11-2009 07:16 AM

The --get-selections option for dpkg, according to "man dpkg" is:
Quote:

--get-selections [package-name-pattern...]
Get list of package selections, and write it to stdout. Without
a pattern, packages marked with state purge will not be shown.
For searching for packages, I like to use aptitude instead of dpkg or apt-cache. To search for a package with aptitude, just run:
Code:

aptitude search package_name
If you don't know the exact name of the package, it will list anything that matches the search term. For example, try running:
aptitude search java
and it will list all the packages with java in their names.
An "i" before the package means that it is installed. And an "A" after the "i" means that the package was automatically installed (for example, as a dependency). A "p" before a package means it is purged (i.e., not installed).

To get more info about a specific package, use:
aptitude show package_name
and you will get detailed info about that package.

The apt-get and aptitude commands differ in how they handle dependencies. Suppose package A has as it's dependencies packages B, C, and D. Both apt-get and aptitude will install the dependencies. But if you remove package A with apt-get, it will leave dependencies B, C, and D on your system, unless you use the --purge option with apt-get.
Aptitude will remove dependencies B, C, and D, as long as they are not needed by other packages.
Keep in mind that synaptic, Add / Remove, and update manager in Ubuntu are GUI front ends for apt-get, not aptitude.
Here is an excellent tutorial on aptitude:
http://algebraicthunk.net/~dburrows/.../rn01re01.html
You should not mix apt-get and aptitude. Be consistent. For best results, wither use apt-get exclusively or aptitude exclusively.

Aptitude is the recommended package manager now in Debian. For Ubuntu though, I would recommend that you use apt-get to be consistent with update manager. If you do not use update manager, synaptic, or Add / Remove, and if you do all updates and package management from the terminal, then it is your choice whether to use apt-get or aptitude.

doru 08-11-2009 11:05 AM

tommcd: Thank you for your answer. It helps me find my way around.

I have a big problem with aptitude, which refuses to search anything but shorthands.
Code:

aptitude search "?name(apt)"
gives:
Code:

E: Regex compilation error: Invalid preceding regular expression
while
Code:

aptitude search ~napt
works well. I just installed Ubuntu server and have no idea what is wrong.

I believe that aptitude should also be a front-end for apt-get. I believe that apt-get and aptitude should work together well, because the tutorial that you mention says that reinstalled packages will not be recorded as reinstalled, because apt-* utilities can not record that information (see http://algebraicthunk.net/~dburrows/...h02s02s03.html). Also, apt-get and aptitude use the same cache. Still, it is wise to be cautious.

aptitude is slower than apt, but it offers very advanced search and info features. I believe that aptitude builds some dependency graph, on every call.

apt-get autoremove removes automatically installed dependencies. apt-get --purge-unused should do the same.

After all this reading, I still have no idea what could be the difference between
Code:

dpkg -l | wc -l
323
and
dpkg -l \* | wc -l
852

Sure the number of available packages in Ubuntu is bigger than 852.

Thanks for your answer!

tommcd 08-12-2009 05:43 AM

Quote:

Originally Posted by doru (Post 3639333)
I have a big problem with aptitude, which refuses to search anything but shorthands.

The "?" and "~" are wild cards when searching with aptitude. I use them this way (using java as an example):
Code:

aptitude search java?
Are you unable to use aptitude to search without the wild cards? What happens if you just run:
Code:

aptitude search java
You should get a list of all the java packages.
Quote:

Originally Posted by doru (Post 3639333)
I believe that aptitude should also be a front-end for apt-get. I believe that apt-get and aptitude should work together well...

Aptitude is not a front end for apt-get. They are similar, but they do handle dependencies slightly differently. I don't see any reason to use both apt-get and aptitude for installing and removing packages. On the other hand, I have experimented in Debian with both apt-get and aptitude to see how each command handles installing and removing packages. I never had a problem switching between apt-get and aptitude. If you hang out in the Debian forums, you will find that many long time Debian users use apt-get; while many others use aptitude. Some say apt-get is better; and some say aptitude is better. The one thing they all seem to agree on though, is that you should pick one or the other and stick with it. If you have been using aptitude and want to switch back to apt-get, I have read that it is a good idea to first run:
Code:

aptitude keep-all
to cancel any pending actions that aptitude may have set.
BTW, that tutorial I linked to is essentially the same as "man aptitude".
Quote:

Originally Posted by doru (Post 3639333)
After all this reading, I still have no idea what could be the difference between
Code:

dpkg -l | wc -l
323
and
dpkg -l \* | wc -l
852

Sure the number of available packages in Ubuntu is bigger than 852.

The dpkg -l lists installed packages. The pipe into wc -l just counts the number of lines in the output, which is the same as the number of installed packages.
For what it's worth, here is what I get when I run:
Code:

dpkg -l | wc -l
1276

and:
Code:

dpkg -l \* | wc -l
3107

I guess the reason I get more packages is because I have a full Ubuntu install, while you have the server version. I do not know what the \* is supposed to do with the dpkg command. Do you know?
Just out of curiosity, what are you trying to learn from using these 2 dpkg commands?

doru 08-12-2009 06:22 AM

Quote:

Originally Posted by tommcd (Post 3640224)
The "?" and "~" are wild cards when searching with aptitude. I use them this way (using java as an example):
Code:

aptitude search java?

~ and ? are escape characters in aptitude, they introduce search patterns. There is no point in adding ? there.

Quote:

Originally Posted by tommcd (Post 3640224)
Aptitude is not a front end for apt-get. [...]

Thanks for the great info.

Quote:

Originally Posted by tommcd (Post 3640224)
The dpkg -l lists installed packages. The pipe into wc -l just counts the number of lines in the output, which is the same as the number of installed packages.
For what it's worth, here is what I get when I run:
Code:

dpkg -l | wc -l
1276

and:
Code:

dpkg -l \* | wc -l
3107

I guess the reason I get more packages is because I have a full Ubuntu install, while you have the server version. I do not know what the \* is supposed to do with the dpkg command. Do you know?
Just out of curiosity, what are you trying to learn from using these 2 dpkg commands?

I started with Ubuntu one week ago. First priority, after basic config, was how to manage packages. Examples on the net used apt-get, so I went into it. I needed to get a list of installed packages on my system, one on a line, for grep and future reference. The solution seemed to be dpkg -l, as apt-cache was overdoing it. That's how I got here. apt-cache show . shows many more packages then dpkg -l \*, and apt-cache pkgnames even more packages. I thought that, if I understand which are the differences between these commands, I will understand better the package management system in Ubuntu.

My system uses apt-get for regular upgrades, and it came with aptitude preinstalled.

apt-get man: "Several "front-end" interfaces exist, such as dselect(8), aptitude, synaptic, gnome-apt and wajig."


All times are GMT -5. The time now is 03:48 PM.