MacOS – How to change the GNU Make’s (default) default location of gcc

homebrewmacosterminalxcode

I run Mac OS X El Capitan 10.4. I have used brew to install Compilation Tools (https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/).

Now when I run make, it still appends to:

 /Applications/Xcode.app/Contents/Developer/usr/bin/g++ -c -pipe -stdlib=libc++ -fstack-protector-all --param ssp-buffer-size=1 -O2 -std=gnu++11 -isysroot 

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.7 -pthread -fdiagnostics-show-option -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter -Wstack-protector -fPIC -DENABLE_WALLET -DBOOST_THREAD_USE_LIB -DBOOST_SPIRIT_THREADSAFE -DUSE_NATIVE_I2P -DUSE_NUM_NONE -DUSE_FIELD_INV_BUILTIN -DUSE_SCALAR_INV_BUILTIN -DUSE_FIELD_10X26 -DUSE_SCALAR_8X32 -DQT_DISABLE_DEPRECATED_BEFORE=0 -DUSE_UPNP=1 -DMINIUPNP_STATICLIB -DSTATICLIB -DHAVE_BUILD_INFO -DMAC_OSX -DMSG_NOSIGNAL=0 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -Isrc -Isrc/json -Isrc/qt -Isrc/tor -Isrc/qt/plugin

Now, I want it to be changed to

/usr/local/bin/g++

So, how to?

Best Answer

Add the following line to your .bash_profile:

export PATH=/usr/local/bin:$PATH

To be sure that will work, restart the terminal and then:

echo $PATH

This will output your PATH variable. The order of directories in PATH variable matters. So, in order to work as you mention, the result should start with /usr/local/bin: