Install two versions of gcc gfortran compiler

I am currently running the latest gcc compiler (version 12.x), but I need to install the an old version of gcc (version 9) to compile some old fortran codes that generate errors when compiled with the most recent gcc compiler.

My question now, is there a way to install two versions of gcc on the same machine? Is there a safer way to do this without messing up the system by replacing the new gcc with the old one?

P.S: I tried installing gcc9 using yay -S gcc9 but the process took more than 2 hours and I had to cancel it due to many fail status for different tests conducted during the installation.

Arch wiki has a lot of references to older versions.

https://wiki.archlinux.org/title/GNU_Compiler_Collection

I don’t know if it’s possible.

Perhaps the chaotic aur repo has the precompiled - but with this you are on your own - and remember this - it is important with relation to AUR and Chaotic - the packages are built using Arch stable and Manjaro stable is 2-4 weeks behind Arch - so if you decide to go down this road - switch to unstable branch before doing anything else.

I suggest you do some testing using docker container or a virtual machine.

Manjaro docker container can be downloaded form the web site.

You could download one as standalone from the official website and use it without installation. Configure your project to use that one through its absolute path. You can manually delete it when you’re done.

Can you please elaborate on how to do this?

How to have installed and how to use several versions is actually mentioned in the Arch Wiki linked above, so you might not need the second approach …

The above link only mentions the availabe gcc versions. It doesn’t show any steps on how to install multiple versions of gcc and how to resolve their conflicts.


So you can have 5 different versions installed at the same time. Even versions for different processors (ARM …)

1 Like

The mentioned gcc versions don’t conflict so there is nothing to resolve. It can be installed like any other AUR package, however I would recommend to manual way without an AUR helper.

There is (no), nor will there be, a conflict. :man_shrugging:

You did not understand - or try to implement the procedure
and thus check whether your “hunch” was factually correct.

… it isn’t …

you where asking for a solution - because you did not know
you then got it
… and dismissed it

oh well
now you “know” what doesn’t work - when all the while it does :upside_down_face:

Thank you all for your responses. I should have mentioned that I am a linux/Manjaro newbie, so some stuff might not be clear to me.

I have already tried to install gcc9 from AUR using yay helper, but it took forever and it never finished the installation.
I will try to install the package from the GUI and see if it works.

there is also gcc9-bin in AUR - no need to compile it

the previous version (11, 12 is current) is still in the Arch repos (also no need to recompile)

for the older ones there might be -bin files in AUR as well - I did not check

the web site is likely easier to check with than with the pamac GUI interface to it

AUR (en) - Packages

https://aur.archlinux.org/

1 Like

I tried the gcc9-bin package and it was installed successfully and was quite fast.
A dumb question, when I do gcc-9 --version, I can see that the compiler is gcc-9, but when I use it to compile the code make CC=gcc-9 the code still uses gcc-12 to generate the executable. Even when I specify a much older version of gcc that is not installed on my system make CC=gcc-4 the process completes with gcc-12.
Any idea how to tackle this (use make with gcc-9 because the above command does not work)?

Depends highly on the project you want to compile. For example

will only work if it is C code. Not for c++ or Fortran. And even if it is C code, the makefile might be special and don’t care about the CC variable.

Installing a different GCCollection is easy, using it, is usually a lot harder.

1 Like

Then you need to familiarize yourself with how LInux works and in the context Manjaro.

As Manjaro is based on Arch and the vast majority of packages is inherited from Arch - you can learn a lot from using the Arch Wiki.

1 Like

Thank you so much. After spending some time on this, the following worked for me (I need gcc9 with gfortran):

  • Installed gcc9-fortran from the add/remove software GUI (AUR package). The installation process took ~3 hours.

  • Verified that the installation was successful by running the following in the terminal:

    • gcc-9 --version.
      gcc-9 (Arch Linux 9.5.0-1) 9.5.0
      Copyright (C) 2019 Free Software Foundation, Inc.
      This is free software; see the source for copying conditions.  There is NO
      warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
      
    • gfortran-9 --version
      GNU Fortran (Arch Linux 9.5.0-1) 9.5.0
      Copyright (C) 2019 Free Software Foundation, Inc.
      This is free software; see the source for copying conditions.  There is NO
      warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
      
  • Built the code by specifying gcc-9 and gfortran-9 as parameters to the make command as:

    make CC=gcc-9 FC=gfortran-9

The code now works properly.
I appreciate the discussion that helped me in getting this to work.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.