Skip to content

Instantly share code, notes, and snippets.

@application2000
Last active February 21, 2024 03:02
Show Gist options
  • Save application2000/73fd6f4bf1be6600a2cf9f56315a2d91 to your computer and use it in GitHub Desktop.
Save application2000/73fd6f4bf1be6600a2cf9f56315a2d91 to your computer and use it in GitHub Desktop.
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
@clarkdunson
Copy link

Thank you very much!

@YJ-20
Copy link

YJ-20 commented Aug 25, 2021

good!

@pachiras
Copy link

Thank you! You saved me!

@thehappyitguy
Copy link

Thank you!
gcc version 9.4.0

@PierrickPochelu
Copy link

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

I got gcc/g++ version 11.1.0 with similar procedure on 18.04 . Thank you!

@sinugowde
Copy link

sinugowde commented May 16, 2023

Hi All,
I am trying to install GCC12 on ubuntu 20.04.6 LTS (Focal Fossa) os but not able to find GCC12. tried to use the above command but with gcc-12.
can anybody provide any suggestions?

@jasonbeach
Copy link

Hi All, I am trying to install GCC12 on ubuntu 20.04.6 LTS (Focal Fossa) os but not able to find GCC12. tried to use the above command but with gcc-12. can anybody provide any suggestions?

I actually just tried this and it appears that gcc12 and 13 are only available as a package on Ubuntu 22.04 and later. If you want it on earlier versions you'll have to build it from source. 😭

@sinugowde
Copy link

Thanks @jasonbeach for your inputs..

@Shaiken
Copy link

Shaiken commented Jun 2, 2023

thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment