I recently upgraded my Ubuntu version to the latest 20.04 release. Some of my earlier projects (developed on 16.04) were compiling just fine with a gcc version of 5 (gcc-5.4.0).

The default version in Ubuntu 20.04 is gcc-9. I'm trying to switch my gcc version down to 5. I've gone through several posts such as How can I build and install gcc-5.4.0 on Ubuntu 18.04? and How to choose the default gcc and g++ version?, but the fact is that gcc-5 packages aren't even available for 20.04 (see https://packages.ubuntu.com/search?keywords=gcc-5).

As expected, the command

sudo apt install gcc-5  

does not work. Is there a way I can install gcc-5 (and gcc-4) on the latest release of Ubuntu 20.04? It seems like I will somehow have to install packages that are available only in earlier releases such as 16.04 or 18.04.

  • 4
    Does this answer your question? How to use an older version of GCC
    – Kulfy
    May 5, 2020 at 19:43
  • 3
    GCC 5 is in xenial's repository, You can use 16.04's repository temporarily to install gcc-5.
    – Kulfy
    May 5, 2020 at 19:46
  • 2
    I tried using the command - echo "deb old-releases.ubuntu.com/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/xenial.list , but I receive the error - "The repository 'old-releases.ubuntu.com/ubuntu xenial Release' does not have a Release file."
    – V-Red
    May 5, 2020 at 20:19
  • 3
    Xenial is still supported. Replace old-releases with archive
    – Kulfy
    May 5, 2020 at 21:18
  • 2
    Okay perfect, I was able to install gcc-5. Thanks!
    – V-Red
    May 5, 2020 at 22:06

2 Answers 2


As mentioned in the comment section, GCC versions lower than 7 are still available in xenial repository. You can follow the following steps to install gcc-5:

  1. Add xenial to /etc/apt/sources.list

Open sources.list with sudo

sudo vim /etc/apt/sources.list

Add the following lines in the sources.list file

deb http://dk.archive.ubuntu.com/ubuntu/ xenial main
deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe

  1. sudo apt update
  2. sudo apt install g++-5 gcc-5

Reference answer: Install gcc 4.9 at ubuntu 18.04

To change default gcc version to gcc 5 you can follow this link. Below I am adding the steps for completeness.

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 5
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 5

And then select the correct version manually as below:

sudo update-alternatives --config gcc
sudo update-alternatives --config g++

If you find this answer helpful, please also consider upvoting the reference answer from which most of my answer is borrowed.


The only solution that worked for me is:

Manual installing of .deb packages

(sad programmer noises)

  1. Go to http://old-releases.ubuntu.com/ubuntu/pool/universe/g/
  2. Download all .deb packages for gcc compiler version you want, f.e.:
cpp-3.4_3.4.6-6ubuntu5_amd64.deb       lib32g2c0_3.4.6-6ubuntu5_amd64.deb
g++-3.4_3.4.6-6ubuntu5_amd64.deb       libg2c0_3.4.6-6ubuntu5_amd64.deb
g77-3.4_3.4.6-6ubuntu5_amd64.deb       libg2c0-dev_3.4.6-6ubuntu5_amd64.deb
gcc-3.4_3.4.6-6ubuntu5_amd64.deb       libstdc++6-dbg_3.4.6-6ubuntu5_amd64.deb
gcc-3.4-base_3.4.6-6ubuntu5_amd64.deb  libstdc++6-dev_3.4.6-6ubuntu5_amd64.deb
  1. Manually install them by running command, f.e.:
sudo dpkg -i ./gcc-3.4-base_3.4.6-6ubuntu5_amd64.deb 
sudo dpkg -i ./cpp-3.4_3.4.6-6ubuntu5_amd64.deb
sudo dpkg -i ./gcc-3.4_3.4.6-6ubuntu5_amd64.deb

and so on...

Check the console output errors about package dependencies to figure out the package install order.

  • If you encounter error (bug probably) about crossdependency of "g++..." package to "libstdc++..." package and v.v. then run install command to update libstdc++ package with exact version number, f.e.:
sudo apt-get install libstdc++6
  1. Hooray! Use installed gcc (g++) version by, f.e.:
g++-3.4 -v

P.S.: of you're getting missing libs errors try

export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LIBRARY_PATH

before the build

  • 1
    In my case I had to install differents lib (maybe not all was needed) : cpp-4.9_4.9.4-2ubuntu1_amd64.deb libcloog-isl4_0.18.4-2_amd64.deb libisl15_0.18-4_amd64.deb libmpfr4-dbg_3.1.4-1_amd64.deb g++-4.9_4.9.4-2ubuntu1_amd64.deb libcloog-isl-dev_0.18.4-2_amd64.deb libisl-dev_0.22.1-1_amd64.deb libstdc++-4.9-dev_4.9.4-2ubuntu1_amd64.deb gcc-4.9-base_4.9.4-2ubuntu1_amd64.deb libgcc-4.9-dev_4.9.4-2ubuntu1_amd64.deb libmpfr4_3.1.4-1_amd64.deb Jan 25, 2021 at 0:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.