I want to install the latest version of GCC (GNU compiler collection) in Linux Mint 17.3. Currently g++ --version returns 4.8.4, whereas the latest stable release is 5.3.

  • Backporting a more recent version is usually possible, but is also non-trivial. An alternative is a local installation from source. From a cleanliness standpoint, a backport is preferable, though. – Faheem Mitha Mar 27 '16 at 9:24
  • Is there another way to install it, maybe not as a package? – becko Mar 27 '16 at 9:26
  • Yes, as I said above, a local installation is an option. But you need to be careful that you can cleanly uninstall it afterwards. Building a package is a harder process, but easier and cleaner from a maintenance point of view. – Faheem Mitha Mar 27 '16 at 9:27
  • The latest version of Gcc, 9.2, is distributed as source code, if this comment is not deleted by the moderator, then you might find time to read the howto on its original site gcc.gnu.org. Previous answer got deleted for no valid reason IMHO. – bbaassssiiee Oct 28 '19 at 20:53

Your Linux Mint comes pre-installed with a GCC package. So first I would recommend you to check if the package is already present in your system by typing the following command in terminal.

apt-cache search gcc

In case you're not having any such package then use the following command in terminal firstly you've add the following repository:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test

then use the next command:

sudo apt-get update
sudo apt-get install g++-4.7 c++-4.7

There is always basic thing we should learn; take it as prerequisite before linux.. Learn googling... try to do more hard search ...

  • Why would I want to install g++-4.7, which is a lower version than g++-4.8, which I already have? I want to upgrade, not downgrade. – becko Mar 27 '16 at 9:12
  • it was 4.8 and you need to search before for available latest package with apt-cache search gcc i gave you logic but really you downgraded my points gr8 – Vinood NK Maheshwari Mar 27 '16 at 9:15
  • At present this answer seems incoherent. Please explain why the OP would wish to install v4.7 instead of v5, (preferably without cliches about the virtues of hard work). – agc Jul 30 '16 at 15:20
  • replace 4.7 by 4.9 and it works. – Algoman Mar 3 '17 at 11:12

download the latest version of gcc

wget http://www.netgull.com/gcc/releases/gcc-5.3.0/gcc-5.3.0.tar.bz2

use command: tar -xjf to unzip the file

Enter the directory that you unzipped just now, say in $HOME/Downloads/gcc-5.3.0, then type command:

./configure --disable-checking --enable-languages=c,c++,objc 
--disable-multilib --with-system-zlib prefix=/usr/bin/gcc-5.3

Dependency installation:build GCC requires GMP4.2+, MPFR 2.4.0+, and MPC 0.8.0+ and build essential

sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev libc6-dev
sudo apt-get install build-essential

install a C++ compiler

sudo apt-get install g++

Next type:

sudo make install

Edit if you still get errors message like " zlib.h not found!" you can do the below to fix it:

apt-get install zlib1g-dev
  • If you have some errors , please comment. I will update. – GAD3R Mar 27 '16 at 9:34
  • Why --disable-multilib? – becko Mar 27 '16 at 10:15
  • error: gcc/lto-compress.c:28:18: fatal error: zlib.h: No such file or directory – becko Mar 27 '16 at 10:29
  • The link is dead. – einpoklum May 29 '18 at 7:55

I am not quiet sure what should be the lastest, because there are always some latest comes out. But you can install any of them in this way.

Take gcc-8 as example:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-8 g++-8
gcc-8 --version

if you want to select gcc-8/g++-8 with higher priority(20 in this case), you also need to

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 20 --slave /usr/bin/g++ g++ /usr/bin/g++-8

Truth be told I'm simply too lazy to move off 17.3 - it works for me. That being said, I still needed a newer gcc. To compile it repeatedly for different targets I have a bash script (see below) that I modify and run (I'm writing my own toy OS, hence I have to use a specially generated gcc).

Change the directories in the script below to match the directories you have. I keep the compiled version in my own directory so I can easily switch between my compiled version and the system's version. I suggest you do the same. You need to download binutils-2.23.2 as well as the gcc version you are interested in (I'm using 7.1.0 below). Put them into a ~/contrib directory along with the script below.

You might also want to change the line "--enabled-languages=c" to "--enabled-languages=c,c++,objc" - my project only needs C. Another change would be the value of PLATFORM. I use "i686-elf" but that won't work for you (I changed it below to something that will work for 32-bit platform). You can try "x86_64-linux-gnu" for a 64-bit platform.

For the curious - the reason I build it like this is because the gcc build process used to have a bug that prevented rebuilding in the source directory. I do not know if this bug still exists (I last encountered it in 4.8.0), but the only workaround was to explicitly build in a separate directory if you ever wanted to rebuild.

[EDIT: Perform the installation of the dependencies suggested above by GAD3R]


function die() {
   echo $1
   exit 127

export PREFIX=/home/lelanthran/opt/cross
export TARGET=i686-linux-gnu
export PATH="$PREFIX/bin:$PATH"

pushd $PWD &> /dev/null
mkdir -p build-binutils
cd build-binutils
../binutils-2.23.2/configure \
   --target=$TARGET \
   --prefix="$PREFIX" \
   --with-sysroot \
   --disable-nls \
   --disable-werror || die "binutils/config error"
make           || die "binutils/make error"
make install   || die "binutils/make install error"

popd &> /dev/null

pushd $PWD &> /dev/null
mkdir -p build-gcc-7.1.0
cd build-gcc-7.1.0
../gcc-7.1.0/configure \
   --target=$TARGET \
   --prefix="$PREFIX" \
   --disable-nls \
   --enable-languages=c \
   --without-headers || die "gcc/config error"
make all-gcc                  || die "gcc/make all-gcc error"
make all-target-libgcc        || die "gcc/make all-target-libgcc error"
make install-gcc              || die "gcc/make install-gcc error"
make install-target-libgcc    || die "gcc/make install-target-libgcc error"

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.