How to upgrade to Ubuntu 20.04 while keeping lambda stack?

You can run apt-get autoremove to remove unnecessary packages from your system. For more information, see:

https://manpages.ubuntu.com/manpages/focal/man8/apt-get.8.html

autoremove (and the auto-remove alias since 1.1)
autoremove is used to remove packages that were automatically installed to satisfy
dependencies for other packages and are now no longer needed.