1

I'm writting instructions for someone else, and I want to know if I need to include a couple apt install commands in my snippet to make it completely copy/paste-able on a fresh Ubuntu installation.

How do I see if a given program was included with my Ubuntu installation or if I installed it myself later?

They're running the same Ubuntu version as me, so I don't need to know if the program only started being pre-installed in a certain Ubuntu version.

guntbert
  • 13,134
  • Check /var/log/apt/history.log – Stephen Boston Nov 27 '19 at 21:40
  • Or just check whether a representative file is there, for example the binary. ls /usr/bin/something | wc -l or something along those lines. – Henning Kockerbeck Nov 27 '19 at 21:42
  • @StephenBoston I might've installed it months ago, will it still be there? –  Nov 27 '19 at 21:44
  • @HenningKockerbeck I'm not trying to write a script with dependency management. I don't want to touch other people's machines. Surely there's a command for checking what requested an installation? –  Nov 27 '19 at 21:45
  • Usually. You might find a gzipped file. The top of the file will show you the start date. – Stephen Boston Nov 27 '19 at 21:46
  • Unzip all the gzipped files and run grep -E 'Requested|Command' history.log -- or whatever file name (The oldest file will have the highest version number.) You can see those commands that specify install rather than 'upgrade' or whatever. Some entries are rather long (upgrades for example) but otherwise it is an easy parse. – Stephen Boston Nov 28 '19 at 02:12
  • @WinEunuuchs2Unix it's even more of a duplicate of the question linked in that question Is it possible to tell what packages I've installed that aren't in the vanilla install? –  Nov 28 '19 at 03:52
  • @Boris I changed the word "program" in the Title to "package" - I guess that is really what you are asking. Every program (that was installed through apt/aptitude/Software center) is part of a package but a package can contain multiple programs. Feel free to revert my edit if that was not what you meant. – guntbert Nov 28 '19 at 21:26

3 Answers3

0

The easy way to determine if a package is installed by the Ubuntu Desktop Installer is to check if it's included in the ubuntu-desktop metapackage. That's the metapackage that defines what the installer will install:

You can see the list of immediate dependencies using the command: apt depends ubuntu-desktop.

But what if your package is not listed among the immediate dependencies? You can easily find out by testing the package with apt.

For example, let's simulate the removal of nautilus (the Gnome file manager). We will, of course, use the --simulate flag; there is no need to destroy our system to answer this simple question. You can see below that removing nautilus also results in the removal of ubuntu-desktop. This is conclusive proof that nautilus is installed by the Desktop Ubuntu installer:

$ apt remove nautilus --simulate
NOTE: This is only a simulation!
      [...]
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  gnome-shell-extension-desktop-icons nautilus nautilus-share ubuntu-desktop
  ubuntu-desktop-minimal
0 upgraded, 0 newly installed, 5 to remove and 0 not upgraded.
Remv ubuntu-desktop [1.440]
Remv ubuntu-desktop-minimal [1.440]
Remv gnome-shell-extension-desktop-icons [19.10.2-1]
Remv nautilus-share [0.7.3-2ubuntu3]
Remv nautilus [1:3.34.1-1ubuntu1]

Let's expand on that example in two ways. Let's move down the dependency tree and try to remove a sub-dependency (nautilus-data). We do this by changing from remove to autoremove. Also, let's use grep to reduce the output. You can see below that this is an effective way to test any (sub-)dependency of ubuntu-desktop anywhere in the chain of dependencies. The nautilus-data package is installed by the Ubuntu Desktop Installer:

$ apt autoremove nautilus-data --simulate | grep ubuntu-desktop
  session-shortcuts tree ubuntu-desktop ubuntu-desktop-minimal
Remv ubuntu-desktop [1.440]
Remv ubuntu-desktop-minimal [1.440]

Let's look at the case with the opposite result. chrome is NOT a dependency of ubuntu-desktop. It was installed sometime later. Removing it WON'T remove ubuntu-desktop:

$ apt autoremove chrome --simulate | grep ubuntu-desktop
(No output)
user535733
  • 62,253
  • 1
    Is not shotwell in the install programs of the Ubuntu installer. I think the OP is asking if he could tell difference from the regular programs that are installed with installation and programs someone installs after, like chrome. – crip659 Nov 27 '19 at 22:22
  • @crip659 thanks for catching what would indeed confuse. Take a look now and see if it's clearer. – user535733 Nov 27 '19 at 22:30
  • Unfortunately he would get no output also, if he used firefox instead of chrome. Firefox is one of the programs installed with Ubuntu. – crip659 Nov 27 '19 at 22:49
  • @crip659. Another good catch. Edited. – user535733 Nov 27 '19 at 22:59
0

The apt-mark showmanual ... is close to what you want, but it lists things like updates of preinstalled things too. Put the below command string into a file, and run it as a script:

comm -23 <(apt-mark showmanual | sort -u) <(gzip -dc /var/log/installer/initial-status.gz | sed -n 's/^Package: //p' | sort -u)
ubfan1
  • 17,838
-1

I don't think there is any script or program that does what you want. About the only way to tell is to run the Ubuntu live USB and see if there are any programs not on it. A few programs do not get installed, like gparted, it is on 'live' but not on installed version. Have seen a few questions like this.

crip659
  • 551
  • Is there a website or something that keeps track of this? Doesn't need to be a command. –  Nov 27 '19 at 22:30
  • Right now I usually just google "is X installed on Ubuntu". If that doesn't work I start up a $5 instance on DigitalOcean to check, but there must be a better way. –  Nov 27 '19 at 22:34
  • 1
    Can try using synaptic package manager and use the installed(manual) section. That will probably be as close as possible. Some stuff will be from updates, but think you can see those yourself, and weed out what you installed. – crip659 Nov 27 '19 at 23:06