Ubuntu – Update GCC to the 6.3 version

aptccompilergccversions

I want to use some C++ features only available in more recent versions of the language. The problem is UbuntuĀ 15.04 (Vivid Vervet) has 4.9.2 installed and looking at the output I get from apt-get install gcc:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
gcc is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n]

It says it's already the newest version. I don't understand why…

Best Answer

  • The only option exist is to Build it from Sources, since you're running Vivid (15.04) version which has reached EOL (End Of Life).

    1. Download the source code and its prerequisites:

      wget https://ftp.gnu.org/gnu/gcc/gcc-6.3.0/gcc-6.3.0.tar.bz2
      tar jxvf gcc-6.3.0.tar.bz2
      cd gcc-6.3.0
      ./contrib/download_prerequisites
      
    2. Compile the sources (note: this command will differ depending on where you initially saved the .bz2 archive), you can also modify option for build command. In this case we'll use very basic option:

      cd ~
      mkdir gcc-build && cd gcc-build
      ../gcc-6.3.0/configure -v --prefix=$HOME/gcc-6.3.0
      

      NOTE: Make sure you have read the docs to view available option.

    3. Now we are ready to build gcc

      • Run make command to build gcc, this steps will take a long time to complete.

        make
        
      • Once the above phase is finished, you can install built gcc with:

        sudo make install
        

        Once this process has completed, run the command gcc --version to verify that the installation has completed successfully.