How to use Macports version of gcc

OSX Mavericks only support gcc version 4.2.1. Macports, however supports gcc from 4.2 to 4.9. However, when you install gcc through Macports, your new version will not be enabled automatically. Here is a little trick:

sudo port select --list gcc
Available versions for gcc:
    mp-gcc44
    none (active)

The following command will enable your desired version:

sudo port select --set gcc mp-gcc44

You will need to do an extra step: Open a new Terminal and type hash -r to register the change with your system.

Happy coding!

Source: StackOverflow