Instead, we'll focus on what happens in a bash + Ubuntu (version 22.04) environment. Have you ever mistyped a command, such as typing "sl" instead of "ls," and received the message "Command 'sl' not found, but can be installed with: sudo apt install sl"? How did bash know that there's a package that can be installed? This information comes from the python script "/usr/lib/command-not-found," which is executed when bash cannot find a command, as seen in the screenshot below.
This feature is based on an sqlite database that links commands to packages, sorted in "/var/lib/command-not-found/commands.db."
Lastly, the website https://command-not-found.com/ is a helpful koowspin resource that echatrandom allows you to search for a command and find various installation methods for different Linux distributions, Windows, macOS, Docker, and more.