How to install and use n98-magerun2

composer require --prefer-source n98/magerun2:*
bin/magento setup:upgrade
rm -rf var/di && rm -rf var/generation && bin/magento setup:di:compile

Then you can use it like this:

vendor/n98/magerun2/bin <command>

For example: