Updating to gcc 11 on kde neon

December 22, 2021

The latest GCC releases are in the ppa:ubuntu-toolchain-r/test repo but add-apt-repository doesn't work on KDE neon...

When trying to run the following on KDE neon:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test

It gives an error:

Traceback (most recent call last):
  File "/usr/bin/add-apt-repository", line 108, in <module>
    sp = SoftwareProperties(options=options)
  File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 118, in __init__
    self.reload_sourceslist()
  File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 613, in reload_sourceslist
    self.distro.get_sources(self.sourceslist)    
  File "/usr/lib/python3/dist-packages/aptsources/distro.py", line 91, in get_sources
    raise NoDistroTemplateException(
aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for Neon/focal
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 153, in apport_excepthook
    with os.fdopen(os.open(pr_filename,
FileNotFoundError: [Errno 2] No such file or directory: '/var/crash/_usr_bin_add-apt-repository.0.crash'

Original exception was:
Traceback (most recent call last):
  File "/usr/bin/add-apt-repository", line 108, in <module>
    sp = SoftwareProperties(options=options)
  File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 118, in __init__
    self.reload_sourceslist()
  File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 613, in reload_sourceslist
    self.distro.get_sources(self.sourceslist)    
  File "/usr/lib/python3/dist-packages/aptsources/distro.py", line 91, in get_sources
    raise NoDistroTemplateException(
aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for Neon/focal

KDE neon changes the distro name somewhere which confuses the python scripts... so to manually add the repo create the file /etc/apt/sources.list.d/ubuntu-toolchain-r-ubuntu-test-focal.list and add:

deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal main 
deb-src http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal main 

Save it and run apt update then sudo apt install gcc-11 g++-11.

To make it default use

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 90 --slave /usr/bin/g++ g++ /usr/bin/g++-11

(run sudo update-alternatives --config gcc to change it)

and ensure gcc --version shows 11.

Cheers!