Another option comes from installing
fzf (command line fuzzy finder): it's an interactive filter for command-line that can be used with any list, including command history.
You have two alternative ways to install it:
sudo apt install fzf
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install
I suggest the second one because it installs also the key-bindings, while the version in the Ubuntu repositories installs
fzf executable alone.
Key-bindings are important because, once activated, if you press CTRL+R and start typing some text, you can search a command in your history.
In the picture below, you can see that typing
apt instal I got the list of matching commands from my terminal history.
For further details, you can visit the GitHub fzf page.