52

I would like to explore concepts and other new features in C++20, provided by g++ 10. However, I cannot seem to find any resources that allows me to apt-get a g++ 10 online?

What is the easiest way for me to get g++10 installed?

user122049
  • 623
  • 1
  • 5
  • 5

1 Answers1

66

gcc-10 is now available in the Ubuntu tool chains.

Add the PPA and install gcc-10:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt install gcc-10

For g++-10:

   sudo apt install g++-10

At the end you need to update the alternatives for compilers (reference):

#Remove the previous alternatives
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++

#Define the compiler
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 30
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 30

sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc

sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++

#Confirm and update (You can use the default setting)
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
Omid N
  • 160
  • 7
P.P
  • 1,021
  • 8
  • 17
  • It only seems to go up to 9 there? – Jason C Dec 28 '20 at 23:16
  • @JasonC Did you add the PPA? – P.P Dec 28 '20 at 23:24
  • Yup: https://pastebin.com/raw/Efa3hSdk – Jason C Dec 28 '20 at 23:31
  • 1
    hmm...May be, you could upgrade to Bionic or focal? You could also compile gcc yourself from sources if you're willing to take that route. – P.P Dec 28 '20 at 23:44
  • Yeah... :( I'll probably just build it from source. This machine is... let's just say upgrading Ubuntu is probably a deeper rabbit hole than I want to go down right now. Oh well. Thanks. – Jason C Dec 28 '20 at 23:51
  • 4
    @JasonC I've a little script you might find useful for installing gcc from source: https://raw.githubusercontent.com/pponnuvel/commons/master/gcc_install.sh – P.P Dec 29 '20 at 00:59
  • 3
    For those Googling around and finding this answer: You can get 11.1 from the tool chain repository, too! – Gwyneth Llewelyn Dec 21 '21 at 11:56