Many times, we add a hook_update_n to change the schema, perform relevant options for new releases etc. Sometimes running this function manually is required to debug it's working or re-run the logic which may not have been implemented because of failed updates. You can use Drush to run any particular function in this way:
Drush
Use the following function to log message to the terminal/command prompt from a Drush command.
$this->output()->writeln('Display this on terminal.');
You can install as explained in https://modulesunraveled.com/blog/install-drush-7-and-8-and-automatically-switch-versions-based-project.
After that go to settings.php and add the following line in $database array.
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
There might be a situation when you have to install a module programmatically in Drupal 8. You can achieve this with the help of Drush Invoke command. Make sure Drush is working fine on your system before using this function.
//This command will install and enable both devel and admin toolbar.
drush_invoke('pm-enable',['devel','admin_toolbar']);