How do I execute code when a module is installed or uninstalled? Currently, I manually have to add terms one by one every time a module gets installed, and that's not efficient. I'm writing a simple module that needs to automatically install 2 terms every time the module gets installed, and remove them every time the module gets uninstalled.

From Create taxonomy term programmatically on Drupal 8, I learned how to add terms. However, I simply don't know where to put the code. What must I do to achieve it?
Needs to go inside of mymodule.install file

&lt;?php

/*
 * Implements hook_install()
 */
function mymodule_install() {

  // code that creates terms

}

/*
 * Implements hook_uninstall()
 */
function mymodule_uninstall() {

  // code that deletes terms

}