Every time Ubuntu installs a new Linux kernel, the old one is left behind.
This means that if you are regularly updating an Ubuntu system the Grub boot
menu becomes longer and longer with kernels you don't need anymore. those
previous kernels, images and modules are usually just wasting space.
The old kernels are deliberately left installed and on the menu so you can
boot a previous kernel if you have trouble with a new one. But if the new
one works, you can safely uninstall the old kernel, which will also result
in the Grub menu being cleaned up.
To remove all the unused Linux Kernel headers, images and modules, simply
run this command:
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge