I accidentally deleted the directory /lib/modules/5.11.0-22-generic. How can I recover it?

I am on Ubuntu 21.04 (Hirsute Hippo) and I accidentally deleted the 5.11.0-22-generic directory in directory /lib/modules.

How can I recover or reinstall it?


Solution 1:

Keep out of your system files in the first place. It is hard to understand how one can "accidentally" delete that directory. Forgive this rant, but it has to get out of my way.

Presumably, 5.11.0-22 is not the kernel you are currently running. Otherwise, you would not be able to restart.

You can reinstall that kernel image with the command

sudo apt install --reinstall linux-headers-5.11.0-22-generic linux-modules-5.11.0-22-generic linux-modules-extra-5.11.0-22-generic

The --reinstall option should indicate apt to effectively redownload and reinstall the package. That should bring back in any missing files.