Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In Gentoo there is the file /var/lib/portage/world that contains packages that I explicitly installed. By explicit I mean, packages that I choose, not including anything installed by default, or pulled in by the dependencies.

Is there a similar file or a command to find that information in Ubuntu?

share|improve this question
@Stefan: no "hi" and "thanks" in a question? – phunehehe Oct 29 '10 at 13:41
I can't find it right now, but there's a FAQ somewhere that states that on StackExchange you shouldn't use "hi" and "thanks", just post the question :) – Joril Oct 29 '10 at 13:56
Thanks, I found it in a meta, gonna edit my questions and answers in a while meta.stackoverflow.com/questions/2950/… – phunehehe Oct 29 '10 at 15:08
I don't know about the thanks really. But hi is out.. :) – Stefan Oct 29 '10 at 19:53
There is a quite good answer on this similar question at Super User. There may be complementary information on this similar question at Ask Ubuntu. – Gilles Oct 29 '10 at 22:45

6 Answers

up vote 15 down vote accepted

NOTE: In the second section, I included a "wrong path" that I went down because I think it is illustrative. If you are just looking for the commands to run, look towards the bottom of that section.


One way to think about this problem is to break this into three parts:

  • How do I get a list of packages not installed as dependencies?
  • How do I get a list of the packages installed by default?
  • How can I get the difference between these two lists?

How do I get a list of packages not installed as dependencies?

The following command seems to work on my system:

$ aptitude search '~i !~M' | cut -d" " -f4 | sort -u > currentlyinstalled.txt

Similar approaches can be found in the links that Gilles posted as a comment to the question. Some sources claim that this will only work if you used aptitude to install the packages; however, I almost never use aptitude to install packages and found that this still worked. The | sort -u sorts the file and removes duplicates. This makes the final step much easier.

How do I get a list of the packages installed by default?

This is a bit trickier. I initially thought that a good approximation would be all of the packages that are dependencies of the meta-packages ubuntu-minimal, ubuntu-standard, ubuntu-desktop, and the various linux kernel related packages. A few results on google searches seemed to use this approach. To get a list of these dependencies, I did the following:

$ apt-cache depends ubuntu-desktop ubuntu-minimal ubuntu-standard linux-* | awk '/Depends:/ {print $2}' | sort -u

However, this seems to leave out some packages that I know had to come by default. I still believe that this method should work if one constructs the right list of metapackages.

However, it seems that Ubuntu mirrors contain a "manifest" file that contains all of the packages in the default install. The manifest for my system is here:

http://mirror.pnl.gov/releases/maverick/ubuntu-10.10-desktop-amd64.manifest

If you search through this page(or the page of a mirror closer to you):

http://mirror.pnl.gov/releases/maverick/

You should be able to find the ".manifest" file that corresponds to the version and architecture you are using. To extract just the package names I did this:

wget -qO - http://mirror.pnl.gov/releases/maverick/ubuntu-10.10-desktop-amd64.manifest | cut -d" " -f1 | sort -u > defaultinstalled.txt

The list was likely already sorted and unique, but I wanted to be sure it was properly sorted to make the next step easier. I then put the output in defaultinstalled.txt.

How can I get the difference between these two lists?

This is the easiest part since most Unix-like systems have many tools to do this. The comm tool is one of many ways to do this:

comm -23 currentlyinstalled.txt defaultinstalled.txt

This should print the list of lines that are unique to the first file. Thus, it should print a list of installed packages not in the default install.

share|improve this answer
What does your first pipeline do that aptitude search '~i!~M' -F %p doesn't? – ephemient Oct 30 '10 at 4:57
@ephemient: Probably nothing. I don't know much about aptitude and thus used tools I'm familiar with rather than digging around in the man file of a program I never use. – Steven D Oct 30 '10 at 16:38
You kind of destroy my hope, I thought there was some standard easy way :( – phunehehe Nov 2 '10 at 1:31
Heh, so did I. I'm not an Ubuntu guru so I'd be happy to see an easier solution if somebody can find one. – Steven D Nov 2 '10 at 4:29

Here's some sample output of cat /var/log/apt/history.log:

Start-Date: 2011-01-22  00:43:38
Commandline: apt-get --target-release experimental install libdbus-1-dev
Upgrade: libdbus-1-3:i386 (1.4.0-1, 1.4.1-1), libdbus-1-dev:i386 (1.4.0-1, 1.4.1-1)
End-Date: 2011-01-22  00:43:48

Start-Date: 2011-01-23  01:16:13
Commandline: apt-get --auto-remove purge webcheck
Purge: python-utidylib:i386 (0.2-6), python-beautifulsoup:i386 (3.1.0.1-2), libtidy-0.99-0:i386 (20091223cvs-1), webcheck:i386 (1.10.3)
End-Date: 2011-01-23  01:16:31

As for your question, filter the stuff with grep (cat /var/log/apt/history.log | grep Commandline).

Note that these files are rotated, so check for others so you don't miss anything:

$ ls /var/log/apt/history.log*
-rw-r--r-- 1 root root 69120 2011-01-23 18:58 /var/log/apt/history.log
-rw-r--r-- 1 root root 19594 2011-01-01 02:48 /var/log/apt/history.log.1.gz

NOTE:

  • I've checked both aptitude and synaptic (versions 0.70 and 0.6.3 respectively), and they both log their activities on that log file. The one setback with them is that they don't have the line starting with Commandline, so the grep trick won't work with them.
share|improve this answer
1  
Interesting solution. You'll need to adjust the grep command a bit to just get a list of packages and to account for packages installed by aptitude and other package managers. If your logs have rotated away, well then you are out of luck. – Steven D Jan 23 '11 at 22:27
@steven Updated. My grep-fu is of a novice, so I'll leave that to the reader. Also, I don't know if the thing rotates away. I only have to files in there myself. – Tshepang Jan 23 '11 at 23:03
Whether they rotate away will depend on your logrotate setup and how long your system has been around. I'm unsure of Ubuntu defaults since it has been a long time since I changed them. – Steven D Jan 24 '11 at 3:40

You would want to have a look at this article.

At the end of the article, there is a python script that should do what you want.

It was written for (k)ubuntu. but should work for Ubuntu aswell.

share|improve this answer

Using dpkg --get-selections will list the packages explicitly requested for installation.

share|improve this answer

According to man apt-mark:

apt-mark showauto
apt-mark showmanual
share|improve this answer
1  
showmanual is showing things like xserver-xorg-video-vesa, which I swear I didn't install manually. – phunehehe Sep 22 '12 at 3:18

Check out /var/log/apt/term.log

share|improve this answer
1  
that's a rather painful way to do things, and there is no distinction between packages I install myself, and those pulled in by dependencies – phunehehe Oct 29 '10 at 7:18
I agree, but I didn't know that apt keeps track of those :/ Now I know, thanks to Stefan :) – Joril Oct 29 '10 at 14:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.