How do I get the history of "apt-get install" on Ubuntu?
I am about do move a server from one Ubuntu box to another. I'm not cloning the old box to the new; I'm creating a new system and will move data as needed. I want to install all the software that I have on the old box on the new one.
Is there a simple way to find the history of all the "sudo apt-get install" commands I have given over time? That is, dpkg -l shows me all the packages that have been installed, but not which top-level package installed them. If there is a way for dpkg to give me the installing package, I can find the unique ones there; otherwise, I want something else to say "you installed these 24 packages".
The apt
history is in /var/log/apt/history.log
as said in a comment above. That said, this will not list packages that were installed manually, using dpkg
or GUIs such as gdebi
. To see all the packages that went through dpkg
, you can look at /var/log/dpkg.log
.
You can list packages whose installation has been explicitly requested with apt-mark
.
apt-mark showmanual
In case you're running an ancient release of Debian, here's a manual way.
The following command gives the list of packages whose installation was requested, whether manually or automatically. Unless you're in the middle of (de)installing packages, this is the list of installed packages.
dpkg --get-selections | sed -n 's/\t\+install$//p'
The following command gives a superset of automatically installed packages:
</var/lib/apt/extended_states awk -v RS= '/\nAuto-Installed: *1/{print$2}'
Putting it all together, the following command lists manually installed packages:
comm -23 <(dpkg --get-selections | sed -n 's/\t\+install$//p') \
<(</var/lib/apt/extended_states \
awk -v RS= '/\nAuto-Installed: *1/{print$2}' |sort)