4

I would like to install gcc-7 on Ubuntu 22.04.

I used:

sudo apt-get install gcc-7 g++-7

But got the error:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package g++-7 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package gcc-7 is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source

E: Package 'gcc-7' has no installation candidate E: Package 'g++-7' has no installation can

How can I install it on my machine?

Kind regards

didate

  • GCC7 is the default in 18.04. For 22.04, the default is GCC11, and GCC7 is not available for obvious reasons. – mikewhatever May 06 '22 at 09:28
  • 1
    But is it possible for me to install it? –  May 06 '22 at 09:32
  • It is not impossible, but might not be a good idea for 22.04. Also, something installed, doesn't mean it is going to work. – mikewhatever May 06 '22 at 13:03
  • 1
    You can have as many versions of gcc as you want, installed at the same time. ..... Using examples : export CC=gcc-7 CXX=g++-7 && [command] ...... and CC=gcc-7 CXX=g++-7 cmake ../ ......... Add a (temporary) line to "sources.list" : deb [url] focal main universe to install g++-7 – Knud Larsen May 06 '22 at 15:09

2 Answers2

12

Thanks @Knud Larsen for that solution.

I had the same problem, I need the old version for the distcc server. The client system, a weak industrial PC cannot be updated.

So the solution is simple, I didn't think of it, but it works. For the records, I added:

deb [arch=amd64] http://archive.ubuntu.com/ubuntu focal main universe

to /etc/apt/sources.list and

ran: apt update; apt install g++-7

Jodeli
  • 129
  • please how to add deb [arch=amd64] http://archive.ubuntu.com/ubuntu focal main universe to /etc/apt/sources.list – daren -2022 Jul 05 '22 at 00:19
  • @daren-2022 Edit that file to add this line. Since it is a system file, you will need sudo. – Archisman Panigrahi Jul 05 '22 at 03:06
  • 2
    For anyone who see this, please be careful doing this. Mixing two versions of Ubuntu on the same installation can be a Really Bad Idea (though admittedly I've been guilty of doing it in some instances). I don't easily imagine this going wrong, but doing stuff like this can explode on you. – ArrayBolt3 Sep 20 '22 at 13:13
  • 1
    It's critical, of course, and it won't work well for most other packages. It will only work for packages that are already designed to be installed in different versions at the same time, like gcc, g++, qt, etc. I have therefore removed this line from /etc/apt/sources.list after installing the minor version of g++ to avoid further problems and also to speed up "apt update" – Jodeli Sep 27 '22 at 07:44
0

I would reccommend installing gcc-7 with brew. That way, it is not permanently added to your system and you can remove it when you no longer need it.

Just run brew install gcc@7

However, DO NOT USE BREW for anything that requires admin rights. It will not work.