10

How do I install the latest gcc on FreeBSD and set up the system so that this latest version would be used to compile further programs?

At the moment of this writing, the latest release of gcc is version 4.9.0. And I use FreeBSD 10.0.

I actually need g++, the C++ compiler; but I need to install something like gcc49 package for it, right?

  • Dp you want to compile all ports with GCC or do you need just GCC? – Raphael Ahrens May 16 '14 at 14:49
  • I would like gcc to compile my software. And maybe the ports I would install after that, if that can be done. – Nickolai Leschov May 16 '14 at 14:51
  • Remember that there are are different branches you can download software from on FreeBSD: unix.stackexchange.com/a/433876/128489 – Mateusz Piotrowski Mar 27 '18 at 17:43
16

You can install GCC 4.9 by building it from ports with

cd /usr/port/lang/gcc49; make install clean

or if you have portmaster

portmaster -DHB lang/gcc49

or if you prefer packages with

pkg install lang/gcc49

If you change lang/gcc49 to lang/gcc you will install the most recent stable version of GCC currently this is GCC 4.7.

When you want to build all your ports with GCC instead of Clang you have to edit /etc/make.conf and add

.if !empty(.CURDIR:M/usr/ports/*) && exists(/usr/local/bin/gcc49)
CC=gcc49
CXX=g++49
CPP=cpp49
.endif

and edit /etc/libmap.conf and add there

libgcc_s.so.1   gcc49/libgcc_s.so.1
libgomp.so.1    gcc49/libgomp.so.1
libobjc.so.3    gcc49/libobjc.so.4
libssp.so.0     gcc49/libssp.so.0
libstdc++.so.6  gcc49/libstdc++.so.6

Here is an article from FreeBSD.org which explains this in more detail.

But you don't really need GCC for the ports, all ports that already depend on GCC will use GCC.

Edit:

And yeah g++ will be installed with all GCC ports.

  • 4
    Note that now lang/gcc5 also exists. – PythonNut Oct 2 '14 at 4:19
  • 2
    and lang/gcc7 (December 2017) – nishanths Dec 28 '17 at 5:55
  • lang/gcc would install the newest version of gcc. – user917099 Sep 4 at 4:55
  • @user917099 Not always some times lang/gcc is one or two versions behind. At the time when the answer was written lang/gcc was not pointing at lang/gcc49. – Raphael Ahrens Sep 4 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.