Can I delete folders in /lib/modules/ after calling "apt-get purge"

I've already call apt-get purge to uninstall the old kernels. But some error occured during the purge that caused the folders to be left behind. It said the folder was not empty so it couldn't delete. To free up disk space can I manually delete those folders that I've purged?

1.1M    ./4.15.0-20-generic
60M     ./4.15.0-32-generic <-- I've purged this
60M     ./4.15.0-30-generic <-- and this
236M    ./4.15.0-33-generic <-- this is my current one

Can I also remove some of these packages?

un  linux-headers-4.15.0-20-generic                       <none>                          <none>                          (no description available)
ii  linux-headers-4.15.0-30                               4.15.0-30.32                    all                             Header files related to Linux kernel version 4.15.0
ii  linux-headers-4.15.0-30-generic                       4.15.0-30.32                    amd64                           Linux kernel headers for version 4.15.0 on 64 bit x86 SMP
ii  linux-headers-4.15.0-32                               4.15.0-32.35                    all                             Header files related to Linux kernel version 4.15.0
ii  linux-headers-4.15.0-32-generic                       4.15.0-32.35                    amd64                           Linux kernel headers for version 4.15.0 on 64 bit x86 SMP
ii  linux-headers-4.15.0-33                               4.15.0-33.36                    all                             Header files related to Linux kernel version 4.15.0
ii  linux-headers-4.15.0-33-generic                       4.15.0-33.36                    amd64                           Linux kernel headers for version 4.15.0 on 64 bit x86 SMP
rc  linux-image-4.15.0-20-generic                         4.15.0-20.21                    amd64                           Signed kernel image generic
ii  linux-image-4.15.0-33-generic                         4.15.0-33.36                    amd64                           Signed kernel image generic
un  linux-image-unsigned-4.15.0-20-generic                <none>                          <none>                          (no description available)
un  linux-image-unsigned-4.15.0-33-generic                <none>                          <none>                          (no description available)
rc  linux-modules-4.15.0-20-generic                       4.15.0-20.21                    amd64                           Linux kernel extra modules for version 4.15.0 on 64 bit x86 SMP
ii  linux-modules-4.15.0-30-generic                       4.15.0-30.32                    amd64                           Linux kernel extra modules for version 4.15.0 on 64 bit x86 SMP
ii  linux-modules-4.15.0-32-generic                       4.15.0-32.35                    amd64                           Linux kernel extra modules for version 4.15.0 on 64 bit x86 SMP
ii  linux-modules-4.15.0-33-generic                       4.15.0-33.36                    amd64                           Linux kernel extra modules for version 4.15.0 on 64 bit x86 SMP
rc  linux-modules-extra-4.15.0-20-generic                 4.15.0-20.21                    amd64                           Linux kernel extra modules for version 4.15.0 on 64 bit x86 SMP
ii  linux-modules-extra-4.15.0-33-generic

Solution 1:

Ok so I decided to just take the risk and manually delete the folder under /lib/modules and had no problem rebooting my server.

Solution 2:

You can safely remove the corresponding version of packages to the version of the kernel that you removed. In your example because you are missing the corresponding kernel versions for the following, so you can ask your package manager to also remove:

linux-headers-4.15.0-30
linux-headers-4.15.0-30-generic
linux-modules-4.15.0-30-generic
linux-headers-4.15.0-32
linux-headers-4.15.0-32-generic
linux-modules-4.15.0-32-generic

Solution 3:

I had about 30 /lib/modules directories and modules from kernels no longer in use and I deleted them all freeing up over 5GB of space. I don't know why they don't get deleted when I delete the kernels with ukuu. It seems this hasn't caused a problem yet.

Solution 4:

I also ran into the same predicament. As some of the others mentioned, I was also able to safely delete folders in /lib/modules. I believe the error you ran into was due to a package that couldn't install due to not enough disk space. In my case, I tried fixing the packages with apt-get -f install but ran into a No space left on device error. I was able to successfully remove the old kernels using apt-get autoremove -f. That freed up quite a bit of space. Hope this helps someone.