Where to Install Applications when using Terminal?
As OS X is a UNIX OS at its core you can usually use the installers that come with the open source tools you've mentioned.

Quite often there's some way to install them, usually there's 3 steps to configure, compile, and install the tools.

For stuff like databases and other UNIX tools they might need stuff in a number of places.

In contrast to that a typical Mac application will be just one self-contained application bundle that's supposed to go in to your /Applications folder.

Though it can as well run from your Desktop, Downloads folder, etc. ...