10

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...

Peter Mortensen
  • 933
  • 2
  • 11
  • 17
Fabrício Santana
  • 125
  • 1
  • 1
  • 7
  • 1
    Ubuntu 15.04 is no longer supported, perhaps you should move to a newer version. Old versions of Ubuntu usually do not have the latest versions of packages, you have to upgrade the distribution or install your package from a ppa or build it from source. – Raziman T V Dec 27 '16 at 03:13

2 Answers2

10

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.

muru
  • 193,181
  • 53
  • 473
  • 722
Liso
  • 15,217
  • 3
  • 50
  • 80
  • What does the "-v" option do? I can't seem to find it on https://gcc.gnu.org/install/configure.html – Fabrício Santana Apr 16 '17 at 16:10
  • `-v` stand for `-verbose`. [More information refer to what verbose really is](http://www.computerhope.com/jargon/v/verbose-mode.htm) – Liso Apr 20 '17 at 15:37
  • To which folder is g++6.3 installed when following these steps? To `~/gcc-6.3.0`, to `~/gcc-build` or to some other folder? Shouldn't any of the folders that was created be removed after running these commands or are they all still required? – HelloGoodbye May 18 '17 at 04:25
  • 1
    `tar xzvf gcc-6.3.0.tar.bz2` just prints `gzip: stdin: not in gzip format`; `tar: Child returned status 1`; `tar: Error is not recoverable: exiting now`, so I unpacked the archive with the archive manager. – HelloGoodbye May 18 '17 at 04:42
  • When I run `../gcc-6.3.0/configure -v --prefix=$HOME/gcc-6.3.0`, I get `/usr/bin/ld: cannot find crt1.o: No such file or directory`, `/usr/bin/ld: cannot find crti.o: No such file or directory`, `/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc.a when searching for -lgcc`, `/usr/bin/ld: cannot find -lgcc` and similar errors. – HelloGoodbye May 18 '17 at 04:48
  • Well that did not work. – Astrid May 23 '18 at 19:40
  • This worked for me but I now have 2.4GB in my ~/gcc-6.3.0 directory... maybe a silly question but do I really need all of this, and is there a better place to put it? – Andrew D. King Oct 24 '18 at 17:14
4

Ubuntu 15.04 has reached end of life and has no support, which means no more updates or fixes (security, bugs or features) will be published.

You should update or reinstall with a newer Ubuntu version.

I'll recommend go with 16.10 (9 month support) which already has gcc 6.x branch on official repos.

But you also can go with 16.04 LTS (5 year support) and add a untrusted/unguaranted ppa to get latest gcc versions like this one

Personally, I would choose go with 16.10 and keep updating from official channels to later software/Ubuntu versions without adding (mostly) any ppa.

dgonzalez
  • 6,910
  • 5
  • 19
  • 27