-1

Is there a way to purge all packages installed via apt-get from the very moment you installed the Ubuntu OS, up till this very point?

One could call it a a "mega apt-get purge".

The purpose of this operation to clear the system of everything I've installed so far (from apt) on top of the Ubuntu OS itself. This would bring me the closer to a fresh install of a Ubuntu OS, without any added software (of course, the only thing I'll have left is to clear all non-apt software and individual files I've added, but that is of course another issue).

The reason for this operation is because this is done on a VPS machine in which I can't install and uninstall operating systems in the traditional way; I can indeed use the "rebuild" functionality of my hosting provider but I find it a bit annoying to use from personal reasons so I just want to go closest I can to a fresh install without that.

How will you do the desired "mega apt-get purge"? Thanks.

3
  • 3
    a reinstall? it would take me 17 minutes to do so and get the result you want.
    – Rinzwind
    Feb 10, 2018 at 15:16
  • @Rinzwind I've edited to explain why this is not really an option for me, in that particular case... Feb 10, 2018 at 15:21
  • @user9303970 still not a problem. I have 10+ VPSes for my business and remount my personal partition in all of them ;)
    – Rinzwind
    Feb 10, 2018 at 16:15

2 Answers 2

1

You can use apt with some scripting:

apt list --manual-installed | awk -F "/" '{print $1}' > ~/list
sudo apt-get purge --simulate `cat ~/list | grep -v Listing`

Please remember - you are trying to perform very dangerous operation.
If unsure please do not remove --simulate
.

On system with 555 manually installed packages apt-get writes the following:

After this operation, 4 769 MB disk space will be freed.
You are about to do something potentially harmful.
To continue type in the phrase 'Yes, do as I say!'
?]
Yes, do as I say!Enter

then it stops.

So it is completely bad idea (I have no cat, sudo commands afterwards).
System boots with kernel panic.
I have snapshot, I'll restore it in 5 seconds.


Conclusion: you should use clever manual method - for example determine which services were installed manually (with apt list --manual-installed) and running (with htop, netstat, systemctl, whatever) and then purge only their packages.

2
  • Use it to get a list and than loop through that list as it appears in stdout and purge? Or you'd use a better way? Feb 10, 2018 at 15:54
  • Do not execute the command above if unsure. It may completely break your system.
    – N0rbert
    Feb 10, 2018 at 16:08
-1

If you still have all the logfiles from apt in /var/log/apt , you can do: $grep install /var/log/apt/history.log; zgrep install /var/log/apt/history.log.*.gz , this will show all packages that have been installed on the system through apt.

Removing them in one commandline would take some bash scripting.

Hope this helps.

Not the answer you're looking for? Browse other questions tagged .