Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to install latest gcc on Ubuntu LTS (12.04, 14.04, 16.04)
These commands are based on a askubuntu answer http://askubuntu.com/a/581497
To install gcc-6 (gcc-6.1.1), I had to do more stuff as shown below.
USE THOSE COMMANDS AT YOUR OWN RISK. I SHALL NOT BE RESPONSIBLE FOR ANYTHING.
ABSOLUTELY NO WARRANTY.
If you are still reading let's carry on with the code.
sudo apt-get update && \
sudo apt-get install build-essential software-properties-common -y && \
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
sudo apt-get update && \
sudo apt-get install gcc-snapshot -y && \
sudo apt-get update && \
sudo apt-get install gcc-6 g++-6 -y && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6 && \
sudo apt-get install gcc-4.8 g++-4.8 -y && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8;
When completed, you must change to the gcc you want to work with by default. Type in your terminal:
sudo update-alternatives --config gcc
To verify if it worked. Just type in your terminal
gcc -v
If everything went fine you should see gcc 6.1.1 by the time I am writing this gist
Happy coding!
See my blog post at https://www.application2000.com
@mdhanasar

This comment has been minimized.

Copy link

mdhanasar commented Jun 28, 2016

Worked without any issues on a new install of Ubuntu 16.04. Thank you..

@GHnubsST

This comment has been minimized.

Copy link

GHnubsST commented Jul 17, 2016

worked perfectly thanks.

@AnanthanM

This comment has been minimized.

Copy link

AnanthanM commented Aug 16, 2016

Thank You

@yech1990

This comment has been minimized.

Copy link

yech1990 commented Aug 28, 2016

g++-6 : Depends: gcc-6-base (= 6.1.1-2ubuntu12~16.04) but 6.1.1-3ubuntu11~14.04.1 is to be installed
         Depends: libstdc++-6-dev (= 6.1.1-2ubuntu12~16.04) but it is not going to be installed
 gcc-6 : Depends: cpp-6 (= 6.1.1-2ubuntu12~16.04) but it is not going to be installed
         Depends: gcc-6-base (= 6.1.1-2ubuntu12~16.04) but 6.1.1-3ubuntu11~14.04.1 is to be installed
         Depends: libgcc-6-dev (= 6.1.1-2ubuntu12~16.04) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
@zxshoe

This comment has been minimized.

Copy link

zxshoe commented Sep 21, 2016

This worked fine today.

update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).
`

Selection Path Priority Status

  • 0 /usr/bin/gcc-6 60 auto mode
    1 /usr/bin/gcc-4.8 60 manual mode
    2 /usr/bin/gcc-6 60 manual mode

Press to keep the current choice[*], or type selection number:`

Thanks!

@andrewrech

This comment has been minimized.

Copy link

andrewrech commented Nov 28, 2016

Very helpful, thank you

@jwarlander

This comment has been minimized.

Copy link

jwarlander commented Dec 1, 2016

Thanks, worked great!

I modified it slightly to keep the default 16.04 gcc-5 around:

 sudo apt-get update && \
 sudo apt-get install build-essential software-properties-common -y && \
 sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
 sudo apt-get update && \
 sudo apt-get install gcc-snapshot -y && \
 sudo apt-get update && \
 sudo apt-get install gcc-6 g++-6 -y && \
 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6 && \
-sudo apt-get install gcc-4.8 g++-4.8 -y && \
-sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8;
+# Already installed gcc-5 as part of build-essential; I didn't need this line..
+# sudo apt-get install gcc-5 g++-5 -y && \
+sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5;
@Sakib37

This comment has been minimized.

Copy link

Sakib37 commented Dec 2, 2016

Thanks. Worked perfectly. :)

@ArulrajAnto

This comment has been minimized.

Copy link

ArulrajAnto commented Dec 4, 2016

Hi, i am getting below error while trying to upgrade gcc,

root@compute:/tmp# sudo apt-get update && \

sudo apt-get install build-essential software-properties-common -y &&
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y &&
sudo apt-get update &&
sudo apt-get install gcc-snapshot -y &&
sudo apt-get update &&
sudo apt-get install gcc-6 g++-6 -y &&
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6 &&
-sudo apt-get install gcc-4.8 g++-4.8 -y &&
-sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8;
Hit:1 http://ppa.launchpad.net/ubuntu-toolchain-r/ppa/ubuntu xenial InRelease
Ign:2 http://ubuntu-cloud.archive.canonical.com/ubuntu xenial-updates/newton InRelease
Hit:3 http://in.archive.ubuntu.com/ubuntu xenial InRelease
Hit:4 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial InRelease
Hit:5 http://ubuntu-cloud.archive.canonical.com/ubuntu xenial-updates/newton Release
Get:7 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get:8 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:9 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Fetched 306 kB in 1s (199 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
build-essential is already the newest version (12.1ubuntu2).
build-essential set to manually installed.
software-properties-common is already the newest version (0.96.20.4).
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
cpp-5 : Depends: gcc-5-base (= 5.4.0-6ubuntu116.04.2) but it is not going to be installed
g++-5 : Depends: gcc-5-base (= 5.4.0-6ubuntu1
16.04.2) but it is not going to be installed
gcc-5 : Depends: gcc-5-base (= 5.4.0-6ubuntu116.04.2) but it is not going to be installed
libasan2 : Depends: gcc-5-base (= 5.4.0-6ubuntu1
16.04.2) but it is not going to be installed
libatomic1 : Depends: gcc-5-base (= 5.4.0-6ubuntu116.04.2) but it is not going to be installed
libcc1-0 : Depends: gcc-5-base (= 5.4.0-6ubuntu1
16.04.2) but it is not going to be installed
libcilkrts5 : Depends: gcc-5-base (= 5.4.0-6ubuntu116.04.2) but it is not going to be installed
libgcc-5-dev : Depends: gcc-5-base (= 5.4.0-6ubuntu1
16.04.2) but it is not going to be installed
libgomp1 : Depends: gcc-5-base (= 5.4.0-6ubuntu116.04.2) but it is not going to be installed
libitm1 : Depends: gcc-5-base (= 5.4.0-6ubuntu1
16.04.2) but it is not going to be installed
liblsan0 : Depends: gcc-5-base (= 5.4.0-6ubuntu116.04.2) but it is not going to be installed
libmpx0 : Depends: gcc-5-base (= 5.4.0-6ubuntu1
16.04.2) but it is not going to be installed
libquadmath0 : Depends: gcc-5-base (= 5.4.0-6ubuntu116.04.2) but it is not going to be installed
libstdc++-5-dev : Depends: gcc-5-base (= 5.4.0-6ubuntu1
16.04.2) but it is not going to be installed
libstdc++-5-dev:i386 : Depends: gcc-5-base:i386 (= 5.4.0-6ubuntu116.04.2) but it is not going to be installed
Depends: libgcc-5-dev:i386 (= 5.4.0-6ubuntu1
16.04.2) but it is not going to be installed
Depends: libstdc++6:i386 (>= 5.4.0-6ubuntu116.04.2) but it is not going to be installed
Depends: libc6-dev:i386 (>= 2.13-0ubuntu6) but it is not going to be installed
libstdc++6 : Depends: gcc-5-base (= 5.4.0-6ubuntu1
16.04.2) but it is not going to be installed
libtsan0 : Depends: gcc-5-base (= 5.4.0-6ubuntu116.04.2) but it is not going to be installed
libubsan0 : Depends: gcc-5-base (= 5.4.0-6ubuntu1
16.04.2) but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

please help me to short it out.

@ArulrajAnto

This comment has been minimized.

Copy link

ArulrajAnto commented Dec 4, 2016

root@compute:/tmp# update-alternatives --config gcc
update-alternatives: error: no alternatives for gcc

@HungryHowies

This comment has been minimized.

Copy link

HungryHowies commented Feb 2, 2017

Good Stuff!! thank you worked great on Ubuntu 16.0.4

@AraHaan

This comment has been minimized.

Copy link

AraHaan commented Feb 17, 2017

nice, just need it for clang 3.9 for Travis CI.

@KyCodeHuynh

This comment has been minimized.

Copy link

KyCodeHuynh commented Mar 7, 2017

Hash sum mismatches when running apt-get update can be resolved by flushing metadata. Without the ability to update, the gcc-6 and g++-6 packages won't be available for install.

@S0ulR3av3R

This comment has been minimized.

Copy link

S0ulR3av3R commented Mar 16, 2017

what does the '-y' at the end of the line?

@talland

This comment has been minimized.

Copy link

talland commented Mar 16, 2017

Nice, thank you very much

@jasonbeach

This comment has been minimized.

Copy link

jasonbeach commented Mar 25, 2017

the -y flag causes apt-get to assume "yes" when it would normally prompt you with a yes /no question

@smac89

This comment has been minimized.

Copy link

smac89 commented Apr 20, 2017

This is great
Gcc version 6.2.0

@zheive

This comment has been minimized.

Copy link

zheive commented Apr 21, 2017

Work very well for me, I had problems after update my kernel version with vmware.

Thanks!

@ivanmara555

This comment has been minimized.

Copy link

ivanmara555 commented May 23, 2017

GCC 9.1.0 on Ubuntu 14.04 & 16.04 & 18.04:

sudo apt-get update -y && 
sudo apt-get upgrade -y && 
sudo apt-get dist-upgrade -y && 
sudo apt-get install build-essential software-properties-common -y && 
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && 
sudo apt-get update -y && 
sudo apt-get install gcc-9 g++-9 -y && 
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-9 && 
sudo update-alternatives --config gcc

select gcc-9

@application2000

This comment has been minimized.

Copy link
Owner Author

application2000 commented May 30, 2017

Hopefully it could help someone. Take care and Have a nice day. Cheers.

@peterhanneman

This comment has been minimized.

Copy link

peterhanneman commented Jun 9, 2017

GCC 7.1 on Ubuntu 14.04 & 16.04:

sudo apt-get update -y && \
sudo apt-get upgrade -y && \
sudo apt-get dist-upgrade -y && \
sudo apt-get install build-essential software-properties-common -y && \
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
sudo apt-get update -y && \
sudo apt-get install gcc-7 g++-7 -y && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 60 --slave /usr/bin/g++ g++ /usr/bin/g++-7 && \
sudo update-alternatives --config gcc
@toffyjan

This comment has been minimized.

Copy link

toffyjan commented Jun 21, 2017

Work very well for me.

Thanks!

@application2000

This comment has been minimized.

Copy link
Owner Author

application2000 commented Jun 22, 2017

@peterhanneman Thank you for the update. Take care

@k-five

This comment has been minimized.

Copy link

k-five commented Jun 24, 2017

thank you ivanmara555 worked on 16.04 LTS..
Sat Jun 24 2017 GMT

@hanzin

This comment has been minimized.

Copy link

hanzin commented Jun 27, 2017

thank you , this work very well !

@jacobtylerdavis

This comment has been minimized.

Copy link

jacobtylerdavis commented Jul 14, 2017

Thank you! This works on Debian as well but instead of adding the Ubuntu repo you can add deb http://ftp.us.debian.org/debian testing main contrib non-free to the end of /etc/apt/sources.list

@smutandwa

This comment has been minimized.

Copy link

smutandwa commented Jul 16, 2017

Thanks, this worked for me on Ubuntu 16.04.

@application2000

This comment has been minimized.

Copy link
Owner Author

application2000 commented Jul 30, 2017

Thanks for the tip @1Forge. Thank you all for your comments. Hope it helps everybody. Happy coding!

@jlettvin

This comment has been minimized.

Copy link

jlettvin commented Aug 14, 2017

Thank you peterhanneman. Your one-liner worked perfectly.

@paberline

This comment has been minimized.

Copy link

paberline commented Aug 21, 2017

This is gold dust! Many thanks.

@komeilr

This comment has been minimized.

Copy link

komeilr commented Aug 24, 2017

Bro are you serious right now?! This worked like a fucking dream!

@NemoDomum

This comment has been minimized.

Copy link

NemoDomum commented Sep 7, 2017

Thank you, solved an issue on Ubuntu 17.04

@justinjk007

This comment has been minimized.

Copy link

justinjk007 commented Sep 8, 2017

Thank you very much. Upgraded from 5 to 6.3

@BeErikk

This comment has been minimized.

Copy link

BeErikk commented Sep 17, 2017

Thanks, confirmed works on WSL Ubuntu 16.04

@SwapnilBorse123

This comment has been minimized.

Copy link

SwapnilBorse123 commented Sep 18, 2017

worked fine! Thanks a lot :)

@MostertMB

This comment has been minimized.

Copy link

MostertMB commented Oct 7, 2017

Excellent! Still works from 4.9.3 to 6.3! Very helpful thank you!

@siebeniris

This comment has been minimized.

Copy link

siebeniris commented Nov 10, 2017

excellent! thanks very much!

@ghost

This comment has been minimized.

Copy link

ghost commented Nov 16, 2017

Thank you! Such good directions. Worked like a charm.

@RianWardana

This comment has been minimized.

Copy link

RianWardana commented Nov 28, 2017

It works. Thanks!

@vikchopde

This comment has been minimized.

Copy link

vikchopde commented Dec 30, 2017

Thanks .Very helpfull !!

@zixuan75

This comment has been minimized.

Copy link

zixuan75 commented Jan 1, 2018

This is not correct. if i type "sudo apt-get install gcc-6 g++-6 -y" command, it says "E: Unable to locate package gcc-6" and then "E: Unable to locate package g++-6" and then "E: Couldn't find any package by regex 'g++-6'".

@thinkjrs

This comment has been minimized.

Copy link

thinkjrs commented Jan 11, 2018

Thanks @peterhanneman!

@NickWoodhams

This comment has been minimized.

Copy link

NickWoodhams commented Jan 25, 2018

Great work. 4.8 worked fantastically to compile mysql-python 1.2.5. Thanks!

@cryptomaniac26

This comment has been minimized.

Copy link

cryptomaniac26 commented Feb 2, 2018

Awesome walk through. In detail and no nonsense! Thank you

@awwsmm

This comment has been minimized.

Copy link

awwsmm commented Feb 16, 2018

Works great! Thanks.

@bryceschober

This comment has been minimized.

Copy link

bryceschober commented Mar 5, 2018

WARNING @application2000 @mdhanasar @GHnubsST @@AnanthanM @yech1990 @zxshoe @andrewrech @jwarlander @Sakib37 @ArulrajAnto @HungryHowies @AraHaan @KyCodeHuynh @S0ulR3av3R @talland @jasonbeach @smac89 @zheive @ivanmara555 @peterhanneman @toffyjan @k-five @hanzin @smutandwa @jlettvin @paberline @komeilr @NemoDomum @justinjk007 @SwapnilBorse123 @MostertMB @siebeniris @amendment19 @RianWardana
@vikchopde @zixuan75 @thinkjrs @NickWoodhams @cryptomaniac26 @awwsmm

The ppa:ubuntu-toolchain-r/test has old compiler builds that don't correctly compile some dkms kernel drivers, like nVidia, and you can get your installation pretty broken with the compilers from this PPA. See this launchpad issue for details.

@starjasmine

This comment has been minimized.

Copy link

starjasmine commented Mar 8, 2018

That article is really informative! Thanks.

@stefson

This comment has been minimized.

Copy link

stefson commented Mar 9, 2018

This might not be the right place to ask for it, but is there a possibility to install llvm + clang 5 toolchain for ubuntu 14.04 for armhf? I found ppa which has x86 and amd64, also 16.04 and newer have it in their repos? gcc is a bit buggy on arm, and also very demanding with memory consumption -_- where clang is just a blast. Faster in compiling, memory cut down by 50 to 80% (tested with amd64 and firefox), and also faster binaries.

Will llvm-4 and llvm-5 be added to trusty, as firefox seems to now depend on at least llvm-4?

@JorgeFrancoIbanez

This comment has been minimized.

Copy link

JorgeFrancoIbanez commented Mar 16, 2018

It works, for me when I've tried to install strongswan from source code! 👍

@Lakshmikanthaks

This comment has been minimized.

Copy link

Lakshmikanthaks commented Mar 18, 2018

It works, thank you :)

@heartonbit

This comment has been minimized.

Copy link

heartonbit commented Mar 20, 2018

Thanks, it works!

@ODYTRON

This comment has been minimized.

Copy link

ODYTRON commented Mar 27, 2018

Works like a charm!

@rkosti

This comment has been minimized.

Copy link

rkosti commented Apr 11, 2018

works perfectly!

@ivanmara555

This comment has been minimized.

Copy link

ivanmara555 commented Apr 25, 2018

GCC 9.1.0 on Ubuntu 14.04 & 16.04 & 18.04:

sudo apt-get update -y && 
sudo apt-get upgrade -y && 
sudo apt-get dist-upgrade -y && 
sudo apt-get install build-essential software-properties-common -y && 
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && 
sudo apt-get update -y && 
sudo apt-get install gcc-9 g++-9 -y && 
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-9 && 
sudo update-alternatives --config gcc

select gcc-9

@cortical-iv

This comment has been minimized.

Copy link

cortical-iv commented Apr 27, 2018

ivanmara555 thanks that works great on my Ubuntu 16 install!

@dustars

This comment has been minimized.

Copy link

dustars commented May 2, 2018

THANK YOU! I have been searching for a solution nearly 10 hours, and finally your method works for me!

@ivanmara555

This comment has been minimized.

Copy link

ivanmara555 commented May 3, 2018

method above now install gcc 8.1.0 ... Congratulations!)

@F001

This comment has been minimized.

Copy link

F001 commented May 8, 2018

@ivanmara555 , I used above command, but only gcc 8.0.1 is installed (not 8.1.0).

gcc --version
gcc (Ubuntu 8-20180424-0ubuntu1~16.04.1) 8.0.1 20180424 (experimental) [trunk revision 259590]

My platform is Ubuntu 16.04.4 LTS. Could you please help to point out what's wrong?

@adrien1018

This comment has been minimized.

Copy link

adrien1018 commented May 10, 2018

@F001 I got into the same situation on Ubuntu 14.04.5 LTS.

@ghost

This comment has been minimized.

Copy link

ghost commented May 12, 2018

Many thanks.. it works greats :)

@nikunjsoni24

This comment has been minimized.

Copy link

nikunjsoni24 commented May 14, 2018

Worked, Thank you very much

@roshanashraf

This comment has been minimized.

Copy link

roshanashraf commented May 19, 2018

thanks

@bobuntu

This comment has been minimized.

Copy link

bobuntu commented May 21, 2018

Nicely done and much appreciated. Thank you @ivanmara555 et al.

@MaitreManuel

This comment has been minimized.

Copy link

MaitreManuel commented Jul 17, 2018

Love you sir, it worked !

@erictarn

This comment has been minimized.

Copy link

erictarn commented Aug 9, 2018

sudo apt-get install python-software-properties needed for Ubuntu 12.04 in order to run add-apt-repository

@seanshpark

This comment has been minimized.

Copy link

seanshpark commented Aug 13, 2018

Thank you!

@seergjej

This comment has been minimized.

Copy link

seergjej commented Aug 22, 2018

http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu/dists/jessie/main/binary-amd64/Packages 404 Not Found

The whole jessie folder is gone. All other distros are there.

@siyavashvafshar

This comment has been minimized.

Copy link

siyavashvafshar commented Aug 26, 2018

Great !! saved a lot of time.

@88plug

This comment has been minimized.

Copy link

88plug commented Aug 27, 2018

Here is the Docker friendly format

FROM ubuntu:18.04
RUN apt-get update ; apt-get upgrade -y ; apt-get install -y gcc-8 g++-8 && \
  update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-8 && \
  update-alternatives --config gcc

also available on https://hub.docker.com/r/88plug/gcc-8-ubuntu-18.04/

@sorgina13

This comment has been minimized.

Copy link

sorgina13 commented Sep 23, 2018

Thank you!

@UsmanMaqbool

This comment has been minimized.

Copy link

UsmanMaqbool commented Oct 2, 2018

thanks a lot :)

@KingOfMezi

This comment has been minimized.

Copy link

KingOfMezi commented Nov 4, 2018

hi...
guide to install the update of GCC 8.2 or GCC 9.0 in Ubuntu 14.04 and 16.04 ???

@bin-y

This comment has been minimized.

Copy link

bin-y commented Nov 5, 2018

Thanks!

@lisneyc

This comment has been minimized.

Copy link

lisneyc commented Nov 8, 2018

Thank you @peterhanneman.

@oaix

This comment has been minimized.

Copy link

oaix commented Nov 14, 2018

Thank you very much @ivanmara555
I test on ubuntu 16.04.5 without upgrading:

sudo apt-get update -y && 
sudo apt-get install build-essential software-properties-common -y && 
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && 
sudo apt-get update -y && 
sudo apt-get install gcc-8 g++-8 -y && 
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-8 && 
sudo update-alternatives --config gcc

select gcc-8

And the final version of gcc is 8.1.0. @F001
image

@abst0603

This comment has been minimized.

Copy link

abst0603 commented Nov 27, 2018

Thanks. It works perfectly!

@ZeliangSu

This comment has been minimized.

Copy link

ZeliangSu commented Jan 2, 2019

Thank you a lot but I'm getting confused if the g++ was well install, because I got error during the installation

update-alternatives: error: no alternatives for g++
I was installing main:gcc-6 g++6 then:gcc-7 g++-7

Then when I did g++ -v, I got:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 6.5.0-2ubuntu116.04' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --with-as=/usr/bin/x86_64-linux-gnu-as --with-ld=/usr/bin/x86_64-linux-gnu-ld --program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 6.5.0 20181026 (Ubuntu 6.5.0-2ubuntu1
16.04)

@zimenglan-sysu-512

This comment has been minimized.

Copy link

zimenglan-sysu-512 commented Apr 6, 2019

thanks @peterhanneman
it solves my problem.

@SamehHassanein

This comment has been minimized.

Copy link

SamehHassanein commented May 4, 2019

Not working on UBUNTU 12.04, below the errors

sameh@sameh-HP-EliteBook-2570p:~$ sudo apt-get update && \

sudo apt-get install build-essential software-properties-common -y &&
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y &&
sudo apt-get update &&
sudo apt-get install gcc-snapshot -y &&
sudo apt-get update &&
sudo apt-get install gcc-6 g++-6 -y &&
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6 &&
sudo apt-get install gcc-4.8 g++-4.8 -y &&
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8;
[sudo] password for sameh:
Hit http://security.ubuntu.com precise-security Release.gpg
Hit http://at.archive.ubuntu.com precise Release.gpg
Hit http://at.archive.ubuntu.com precise-updates Release.gpg
Hit http://at.archive.ubuntu.com precise-backports Release.gpg
Hit http://archive.canonical.com precise Release.gpg
Hit http://extras.ubuntu.com precise Release.gpg
Hit http://at.archive.ubuntu.com precise Release
Hit http://at.archive.ubuntu.com precise-updates Release
Hit http://ppa.launchpad.net precise Release.gpg
Hit http://security.ubuntu.com precise-security Release
Hit http://at.archive.ubuntu.com precise-backports Release
Hit http://archive.canonical.com precise Release
Hit http://extras.ubuntu.com precise Release
Hit http://at.archive.ubuntu.com precise/main Sources
Hit http://at.archive.ubuntu.com precise/restricted Sources
Hit http://at.archive.ubuntu.com precise/universe Sources
Hit http://at.archive.ubuntu.com precise/multiverse Sources
Hit http://at.archive.ubuntu.com precise/main i386 Packages
Hit http://at.archive.ubuntu.com precise/restricted i386 Packages
Hit http://at.archive.ubuntu.com precise/universe i386 Packages
Hit http://at.archive.ubuntu.com precise/multiverse i386 Packages
Hit http://at.archive.ubuntu.com precise/main TranslationIndex
Hit http://at.archive.ubuntu.com precise/multiverse TranslationIndex
Hit http://security.ubuntu.com precise-security/main Sources
Hit http://at.archive.ubuntu.com precise/restricted TranslationIndex
Hit http://at.archive.ubuntu.com precise/universe TranslationIndex
Hit http://at.archive.ubuntu.com precise-updates/main Sources
Get:1 http://dl.google.com stable Release.gpg [819 B]
Hit http://at.archive.ubuntu.com precise-updates/restricted Sources
Hit http://at.archive.ubuntu.com precise-updates/universe Sources
Hit http://archive.canonical.com precise/partner i386 Packages
Hit http://extras.ubuntu.com precise/main Sources
Hit http://at.archive.ubuntu.com precise-updates/multiverse Sources
Hit http://at.archive.ubuntu.com precise-updates/main i386 Packages
Hit http://at.archive.ubuntu.com precise-updates/restricted i386 Packages
Hit http://at.archive.ubuntu.com precise-updates/universe i386 Packages
Hit http://at.archive.ubuntu.com precise-updates/multiverse i386 Packages
Hit http://at.archive.ubuntu.com precise-updates/main TranslationIndex
Hit http://security.ubuntu.com precise-security/restricted Sources
Hit http://security.ubuntu.com precise-security/universe Sources
Hit http://security.ubuntu.com precise-security/multiverse Sources
Hit http://security.ubuntu.com precise-security/main i386 Packages
Hit http://security.ubuntu.com precise-security/restricted i386 Packages
Hit http://ppa.launchpad.net precise Release
Hit http://at.archive.ubuntu.com precise-updates/multiverse TranslationIndex
Hit http://at.archive.ubuntu.com precise-updates/restricted TranslationIndex
Hit http://at.archive.ubuntu.com precise-updates/universe TranslationIndex
Hit http://at.archive.ubuntu.com precise-backports/main Sources
Hit http://security.ubuntu.com precise-security/universe i386 Packages
Hit http://security.ubuntu.com precise-security/multiverse i386 Packages
Hit http://security.ubuntu.com precise-security/main TranslationIndex
Hit http://security.ubuntu.com precise-security/multiverse TranslationIndex
Hit http://security.ubuntu.com precise-security/restricted TranslationIndex
Hit http://archive.canonical.com precise/partner TranslationIndex
Hit http://extras.ubuntu.com precise/main i386 Packages
Ign http://extras.ubuntu.com precise/main TranslationIndex
Hit http://at.archive.ubuntu.com precise-backports/restricted Sources
Hit http://at.archive.ubuntu.com precise-backports/universe Sources
Hit http://at.archive.ubuntu.com precise-backports/multiverse Sources
Hit http://at.archive.ubuntu.com precise-backports/main i386 Packages
Hit http://at.archive.ubuntu.com precise-backports/restricted i386 Packages
Hit http://at.archive.ubuntu.com precise-backports/universe i386 Packages
Hit http://at.archive.ubuntu.com precise-backports/multiverse i386 Packages
Hit http://at.archive.ubuntu.com precise-backports/main TranslationIndex
Hit http://at.archive.ubuntu.com precise-backports/multiverse TranslationIndex
Hit http://at.archive.ubuntu.com precise-backports/restricted TranslationIndex
Hit http://archive.canonical.com precise/partner Translation-en
Hit http://security.ubuntu.com precise-security/universe TranslationIndex
Hit http://at.archive.ubuntu.com precise-backports/universe TranslationIndex
Hit http://at.archive.ubuntu.com precise/main Translation-en
Hit http://at.archive.ubuntu.com precise/multiverse Translation-en
Hit http://at.archive.ubuntu.com precise/restricted Translation-en
Hit http://at.archive.ubuntu.com precise/universe Translation-en
Hit http://at.archive.ubuntu.com precise-updates/main Translation-en
Hit http://at.archive.ubuntu.com precise-updates/multiverse Translation-en
Hit http://at.archive.ubuntu.com precise-updates/restricted Translation-en
Hit http://at.archive.ubuntu.com precise-updates/universe Translation-en
Hit http://at.archive.ubuntu.com precise-backports/main Translation-en
Hit http://security.ubuntu.com precise-security/main Translation-en
Hit http://security.ubuntu.com precise-security/multiverse Translation-en
Hit http://at.archive.ubuntu.com precise-backports/multiverse Translation-en
Hit http://at.archive.ubuntu.com precise-backports/restricted Translation-en
Hit http://at.archive.ubuntu.com precise-backports/universe Translation-en
Hit http://ppa.launchpad.net precise/main Sources
Hit http://security.ubuntu.com precise-security/restricted Translation-en
Hit http://security.ubuntu.com precise-security/universe Translation-en
Hit http://dl.google.com stable Release
Ign http://dl.google.com stable Release
Hit http://ppa.launchpad.net precise/main i386 Packages
Ign http://extras.ubuntu.com precise/main Translation-en_US
Ign http://extras.ubuntu.com precise/main Translation-en
Hit http://ppa.launchpad.net precise/main TranslationIndex
Ign http://dl.google.com stable/main TranslationIndex
Hit http://ppa.launchpad.net precise/main Translation-en
Err http://dl.google.com stable/main i386 Packages
404 Not Found [IP: 2a00:1450:4016:80c::200e 80]
Ign http://dl.google.com stable/main Translation-en_US
Ign http://dl.google.com stable/main Translation-en
Fetched 819 B in 3s (228 B/s)
W: GPG error: http://dl.google.com stable Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 6494C6D6997C215E
W: Failed to fetch http://dl.google.com/linux/chrome/deb/dists/stable/main/binary-i386/Packages 404 Not Found [IP: 2a00:1450:4016:80c::200e 80]

@supmit13

This comment has been minimized.

Copy link

supmit13 commented May 20, 2019

Worked like a charm for me. Thanks a ton.

@ivanmara555

This comment has been minimized.

Copy link

ivanmara555 commented May 23, 2019

GCC 9.1.0 on Ubuntu 14.04 & 16.04 & 18.04:

sudo apt-get update -y && 
sudo apt-get upgrade -y && 
sudo apt-get dist-upgrade -y && 
sudo apt-get install build-essential software-properties-common -y && 
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && 
sudo apt-get update -y && 
sudo apt-get install gcc-9 g++-9 -y && 
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-9 && 
sudo update-alternatives --config gcc

select gcc-9

@Newk77

This comment has been minimized.

Copy link

Newk77 commented Jun 15, 2019

Thank you!!

@tgnurulhuda

This comment has been minimized.

Copy link

tgnurulhuda commented Jun 26, 2019

Thanks @peterhanneman

GCC 7.1 on Ubuntu 14.04 & 16.04:

sudo apt-get update -y && \
sudo apt-get upgrade -y && \
sudo apt-get dist-upgrade -y && \
sudo apt-get install build-essential software-properties-common -y && \
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
sudo apt-get update -y && \
sudo apt-get install gcc-7 g++-7 -y && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 60 --slave /usr/bin/g++ g++ /usr/bin/g++-7 && \
sudo update-alternatives --config gcc
@kraj

This comment has been minimized.

Copy link

kraj commented Jul 24, 2019

Just in case if someone wants to make multilib ( gcc/g++ -m32 ) work then they also need to install gcc multilib packages

apt-get install gcc-<ver>-multilib lib32stdc++-<ver>-dev lib32gcc-<ver>-dev lib32objc-<ver>-dev

in my case <ver> is 9

@macdi

This comment has been minimized.

Copy link

macdi commented Sep 30, 2019

GCC 9.1.0 on Ubuntu 14.04 & 16.04 & 18.04:

sudo apt-get update -y && 
sudo apt-get upgrade -y && 
sudo apt-get dist-upgrade -y && 
sudo apt-get install build-essential software-properties-common -y && 
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && 
sudo apt-get update -y && 
sudo apt-get install gcc-9 g++-9 -y && 
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-9 && 
sudo update-alternatives --config gcc

select gcc-9

Thank you very much worked for me as well on 16.04

@ivanmara555

This comment has been minimized.

Copy link

ivanmara555 commented Oct 29, 2019

GCC 9.2.1 on Ubuntu 14.04 & 16.04 & 18.04:

sudo apt-get update -y && 
sudo apt-get upgrade -y && 
sudo apt-get dist-upgrade -y && 
sudo apt-get install build-essential software-properties-common -y && 
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && 
sudo apt-get update -y && 
sudo apt-get install gcc-9 g++-9 -y && 
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-9 && 
sudo update-alternatives --config gcc

select gcc-9

@sreeragh-ar

This comment has been minimized.

Copy link

sreeragh-ar commented Nov 15, 2019

@ivanmara555
Thanks

@Asishinuzuka

This comment has been minimized.

Copy link

Asishinuzuka commented Nov 26, 2019

for gcc-3.4 or any older versions of gcc?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.