# Upgrading gfortran on Ubuntu22 LTS

**URL:** <https://fortran-lang.discourse.group/t/upgrading-gfortran-on-ubuntu22-lts/9154>\
**Category:** GNU\
**Created:** [January 31, 2025, 10:40pm UTC](https://fortran-lang.discourse.group/t/upgrading-gfortran-on-ubuntu22-lts/9154 "2025-01-31T22:40:02Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![septc](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/septc/32/77_2.png) [@septc](https://fortran-lang.discourse.group/u/septc)\
**Post date:** [January 31, 2025, 10:40pm UTC](https://fortran-lang.discourse.group/t/upgrading-gfortran-on-ubuntu22-lts/9154/1 "2025-01-31T22:40:02Z")

</div>

Hello,

I am using Ubuntu22 LTS on my PC and gfortran-11 for all my calculations. This version works very nicely for me, but I would also like to try newer versions (hopefully without compiling from source!) Looking at related threads (e.g. below), it seems that we can install newer versions by `apt` as follows:

- [Gfortran upgrade](https://fortran-lang.discourse.group/t/gfortran-upgrade/8516)

```auto
     sudo add-apt-repository ppa:ubuntu-toolchain-r/test
     sudo apt update
     sudo apt install gfortran-13

```

Here, I am wondering if this method of installation might have some possible “interference” with existing Gfortran versions? For example, does the result / behavior of the older versions could potentially change because of the associated installation of newer libraries or config files? Or, is the installation completely separate (including libraries) and so there is essentially no worry about interference?

Another approach for upgrading Gfortran may be to upgrade the OS itself to Ubuntu 24 LTS (particularly with “in-place” upgrade). But here, I am also worried whether I can install older versions (for comparison and testing), e.g. gfortran-11 that I currently use. I have never tried an in-place OS upgrade, but only “fresh” installation up to now, so I am not sure whether I can keep old compiler environments.

(FWIW, I’ve been using Ubuntu22 also for workstations (!) and wondering if it is a reasonable choice… but I will ask this in a separate thread.)

If you have related experience, I would really appreciate any hints or information.  
Thanks very much!

---

<div class="post-metadata">

**Author:** ![jorgeg](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jorgeg/32/6835_2.png) [@jorgeg](https://fortran-lang.discourse.group/u/jorgeg)\
**Post date:** [January 31, 2025, 10:47pm UTC](https://fortran-lang.discourse.group/t/upgrading-gfortran-on-ubuntu22-lts/9154/2 "2025-01-31T22:47:05Z")

</div>

You can build it yourself! See this website on how to get the gcc repo: [GCC: Anonymous read-only Git access - GNU Project](https://gcc.gnu.org/git.html) basically

```auto
git clone git://gcc.gnu.org/git/gcc.git my_gcc
cd my_gcc
git checkout releases/gcc-14.2.0
contrib/download_prerequisites
./configure --prefix=$HOME/install/compilers/gcc/14.2.0 --enable-languages=c,c++,fortran --enable-libgomp --enable-bootstrap --enable-shared --enable-threads=posix --with-tune=generic --disable-multilib
make -j install

```

Bootstrap with a lower version so if you’re building gcc/14.2.0 use say 11.4 … etc.

If you learn how to build it yourself you’ll stop using apt-get for a bit, since this allows you full control on what to use. You can load the version by creating an env file like:

```auto
export GCCVERSION=x.y.z
export GCC_ROOT=/shared/compilers/gcc/$GCCVERSION
export PATH=$GCC_ROOT/bin:$PATH
export LD_LIBRARY_PATH=$GCC_ROOT/lib64:$LD_LIBRARY_PATH
export LD_RUN_PATH=$GCC_ROOT/lib64:$LD_RUN_PATH
export CPATH=$GCC_ROOT/include:$CPATH
export INCLUDEPATH=$GCC_ROOT/include:$INCLUDEPATH
export CXX=$GCC_ROOT/bin/g++
export CC=$GCC_ROOT/bin/gcc
export FC=$GCC_ROOT/bin/gfortran

```

---

<div class="post-metadata">

**Author:** ![msz59](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@msz59](https://fortran-lang.discourse.group/u/msz59)\
**Post date:** [January 31, 2025, 10:48pm UTC](https://fortran-lang.discourse.group/t/upgrading-gfortran-on-ubuntu22-lts/9154/3 "2025-01-31T22:48:04Z")

</div>

You could also try [Homebrew for Linux](https://docs.brew.sh/Homebrew-on-Linux), getting the newest version (14.2.0 at the moment), completely independent from the “system” repositories

---

<div class="post-metadata">

**Author:** ![septc](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/septc/32/77_2.png) [@septc](https://fortran-lang.discourse.group/u/septc)\
**Post date:** [January 31, 2025, 10:57pm UTC](https://fortran-lang.discourse.group/t/upgrading-gfortran-on-ubuntu22-lts/9154/4 "2025-01-31T22:57:42Z")

</div>

Yeah, I used to build GCC from source when I was younger, but recently I’ve got too much ~~old~~ used to installing from package managers and so become very lazy… (I even use the default apt version of MPI, though I compiled it manually before 😅) So I was wondering about the simplest possible way (maybe apt or other package managers)…

---

<div class="post-metadata">

**Author:** ![septc](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/septc/32/77_2.png) [@septc](https://fortran-lang.discourse.group/u/septc)\
**Post date:** [January 31, 2025, 11:02pm UTC](https://fortran-lang.discourse.group/t/upgrading-gfortran-on-ubuntu22-lts/9154/5 "2025-01-31T23:02:08Z")

</div>

Thanks very much for mentioning Homebrew for Linux. I once used it for trying some compilers, but have not fully explored its usage at that time (I remember I need to carefully set the PATH variable, so as not to mix commands installed with `apt` and `brew`). I will give it another try on Ubuntu22 also.

---

<div class="post-metadata">

**Author:** ![jwmwalrus](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jwmwalrus/32/4483_2.png) [@jwmwalrus](https://fortran-lang.discourse.group/u/jwmwalrus)\
**Post date:** [January 31, 2025, 11:16pm UTC](https://fortran-lang.discourse.group/t/upgrading-gfortran-on-ubuntu22-lts/9154/6 "2025-01-31T23:16:51Z")

</div>

> [@septc](#):
>
> Yeah, I used to build GCC from source when I was younger, but recently I’ve got too much ~~old~~ used to installing from package managers and so become very lazy…

Me too. I remember spending hours watching GCC build, back when subversion was still a thing. 😆

Debian-based distros (like Ubuntu) use an “alternatives” system. So, you can have alongside installations for multiple versions of the same thing, like the PPA method you showed, and use the `update-alternatives` to pick the default.

I’m just not sure if that still works properly for GCC in Ubuntu (since they seem to be moving away from APT).

Docker might be another option…

---

<div class="post-metadata">

**Author:** ![hkvzjal](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/hkvzjal/32/3055_2.png) [@hkvzjal](https://fortran-lang.discourse.group/u/hkvzjal)\
**Post date:** [January 31, 2025, 11:25pm UTC](https://fortran-lang.discourse.group/t/upgrading-gfortran-on-ubuntu22-lts/9154/7 "2025-01-31T23:25:52Z")

</div>

> [@septc](#):
>
> ```auto
> sudo add-apt-repository ppa:ubuntu-toolchain-r/test
> sudo apt update
> sudo apt install gfortran-13
> 
> ```

This is the method I always use and recommend on Ubuntu 22. I have gnu 11, 12 and 13 and never had problems. The default gcc/gfortran versions are the 11 and the newer versions having different names do not conflict. I’ve setup some bash functions to activate/deactivate aliasing to have “gcc”/“gfortran” to point to the desired one. If you install [Miniforge](https://github.com/conda-forge/miniforge) you can also have gnu 14 from within the conda environement.

---

<div class="post-metadata">

**Author:** ![rwmsu](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@rwmsu](https://fortran-lang.discourse.group/u/rwmsu)\
**Post date:** [January 31, 2025, 11:47pm UTC](https://fortran-lang.discourse.group/t/upgrading-gfortran-on-ubuntu22-lts/9154/8 "2025-01-31T23:47:23Z")

</div>

On my Linux Mint systems which are Ubuntu/Debian based, all new versions of gfortran I install using apt get a specific version name. ie gfortran-13 gets installed as /usr/bin/gfortran-13, gfortran-11 gets installed as /usr/bin/gfortran-11. I have never encountered any issues having both installed, ie no conflicts.

---

<div class="post-metadata">

**Author:** ![Marshdweller](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@Marshdweller](https://fortran-lang.discourse.group/u/Marshdweller)\
**Post date:** [February 1, 2025, 5:11am UTC](https://fortran-lang.discourse.group/t/upgrading-gfortran-on-ubuntu22-lts/9154/9 "2025-02-01T05:11:47Z")

</div>

I have GCC/G++/GFortran 11,12,13(built from sources) via update-alternatives. Ubuntu 22 and 24. No issues.

---

<div class="post-metadata">

**Author:** ![dwannetts](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/dwannetts/32/6530_2.png) [@dwannetts](https://fortran-lang.discourse.group/u/dwannetts)\
**Post date:** [February 1, 2025, 12:19pm UTC](https://fortran-lang.discourse.group/t/upgrading-gfortran-on-ubuntu22-lts/9154/10 "2025-02-01T12:19:22Z")

</div>

I’ve never had any issue with multiple versions of `gfortran` on the same system from 10.4 to 24.04.

Like rest of this thread, I’ve usually installed them from the `ppa:ubuntu-toolchain-r/test`.

I switch versions without issue using `update-alternatives`.

---

<div class="post-metadata">

**Author:** ![septc](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/septc/32/77_2.png) [@septc](https://fortran-lang.discourse.group/u/septc)\
**Post date:** [February 11, 2025, 3:02am UTC](https://fortran-lang.discourse.group/t/upgrading-gfortran-on-ubuntu22-lts/9154/11 "2025-02-11T03:02:58Z")

</div>

Hi, I am sorry to be late for reply, and thank you very much for all the information!  
I will try installing GCC \>= 13 via PPA and test it with my codes (+ MPI) to check the results and timing. As for the `update-alternatives` command, I know only the name of it but never tried it up to now… (so I currently use the default GCC11 for all my production runs). I will report back if I hit some issues or more questions. Thanks!
