Install a specific version of an older package by adding an old mirror

I'm attempting to install a specific version of gcc to Ubuntu 18.04.

By default the version of Ubuntu at the time of this writing is 18.04.5. Installing it with sudo apt-get install gcc-7 results in the following:

user@server:~$ gcc-7 -v
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) 
user@server:~$ sudo apt-cache policy gcc-7
gcc-7:
  Installed: 7.5.0-3ubuntu1~18.04
  Candidate: 7.5.0-3ubuntu1~18.04
  Version table:
 *** 7.5.0-3ubuntu1~18.04 500
        500 http://hr.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
        500 http://hr.archive.ubuntu.com/ubuntu bionic-security/main amd64 Packages
     7.3.0-16ubuntu3 500
        500 http://hr.archive.ubuntu.com/ubuntu bionic/main amd64 Packages

Apt recognizes two versions and has installed the 7.5.0-3ubuntu1~18.04 one. I need the version 7.4.0.

I have found a package mirror which has the required package version (gcc-7-multilib_7.4.0-1ubuntu1~18.04.1_amd64.deb) and did the following:

# Add "deb https://mirror.squ.edu.om/ubuntuarchive/ubuntu bionic main restricted multiverse universe" to /etc/apt/sources.list
user@server:~$ sudo apt-get update
user@server:~$ sudo apt-cache policy gcc-7
gcc-7:
  Installed: 7.5.0-3ubuntu1~18.04
  Candidate: 7.5.0-3ubuntu1~18.04
  Version table:
 *** 7.5.0-3ubuntu1~18.04 500
        500 http://hr.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
        500 http://hr.archive.ubuntu.com/ubuntu bionic-security/main amd64 Packages
     7.3.0-16ubuntu3 500
        500 http://hr.archive.ubuntu.com/ubuntu bionic/main amd64 Packages
        500 https://mirror.squ.edu.om/ubuntuarchive/ubuntu bionic/main amd64 Packages

However this only added a new mirror to the 7.3.0-16ubuntu3. It didn't introduce the version 7.4.0-1ubuntu1~18.04 which exists as a package in the mirrors. I expected to see the new versions available.

Am looking for an explanation for this behavior and ways to add the 7.4.0 version?


Solution 1:

Here's one way to do it.

  1. Look at apt changelog gcc-7-multilib to see which older releases of Ubuntu include version 7.4.0. This avoids a lot of mucking about with broken dependencies. Here's the edited list:
    gcc-7 (7.5.0-1ubuntu1) focal
    gcc-7 (7.4.0-15ubuntu1) focal

    gcc-7 (7.4.0-14ubuntu2) eoan
    gcc-7 (7.4.0-14ubuntu1) eoan
    gcc-7 (7.4.0-12ubuntu2) eoan
    gcc-7 (7.4.0-11ubuntu1) eoan
    gcc-7 (7.4.0-10ubuntu2) eoan
    gcc-7 (7.4.0-9ubuntu1) eoan

    gcc-7 (7.4.0-8ubuntu1) disco
    gcc-7 (7.4.0-7ubuntu1) disco
    gcc-7 (7.4.0-6ubuntu1) disco
    gcc-7 (7.4.0-5ubuntu1) disco
    gcc-7 (7.4.0-4ubuntu1) disco
    gcc-7 (7.4.0-3ubuntu2) disco
    gcc-7 (7.4.0-3ubuntu1) disco
    gcc-7 (7.4.0-2ubuntu1) disco
    gcc-7 (7.4.0-1ubuntu1) disco
    gcc-7 (7.3.0-31ubuntu1) disco
  1. You can see that both 19.04 (Disco) and 19.10 (Eoan) shipped with the version you want.

    • Note: Both releases are past End of Life. Neither receives security patches, and neither is supported here at AskUbuntu anymore.
  2. Unsupported releases of Ubuntu are available at https://old-releases.ubuntu.com/releases/ . If you decide to use an old release for a specific purpose, run it in a VM and be sensible about its access to your network.