How to set the default terminal (or window manager, browser, and much more) in Linux

Ever wondered how your Linux system chooses the default Terminal Emulator, web browser, window manager, text editor, particular version of an app (eg, php5 vs 7/python2.7 vs 3)? Wonder no…