Methods to Install OpenFOAM v2412 on Ubuntu

Installing OpenFOAM is the first step toward building a reliable CFD workflow. However, many users are unsure which installation method to choose. OpenFOAM provides multiple installation approaches, each designed for different use cases such as simplicity, portability, or customization.

In this guide, we will install OpenFOAM v2412 on Ubuntu, and more importantly, explain installation using three different methods:

  • Installing using APT (recommended for most users)
  • Installing using Docker (recommended for portability and reproducibility)
  • Installing from source (recommended for advanced users and developers)

Although this guide focuses on OpenFOAM v2412, the same methods can be used to install other versions. Only the specific commands and package names may change.

Method 1: Installing OpenFOAM using APT (Recommended)

This is the simplest and most recommended method for Ubuntu users. It installs precompiled binaries and handles dependencies automatically.

Step 1: Go to the OpenFOAM precompiled binaries page

OpenFOAM provides official installation instructions here:

https://gitlab.com/openfoam/core/openfoam/-/wikis/precompiled

Then navigate to the Ubuntu/Debian binaries page:

https://gitlab.com/openfoam/core/openfoam/-/wikis/precompiled/debian

Step 2: Add the OpenFOAM repository

Run the following command:

curl -s https://dl.openfoam.com/add-debian-repo.sh | sudo bash

This adds the official OpenFOAM repository to your system.

Step 3: Update repository information

sudo apt-get update

Step 4: Install OpenFOAM v2412

sudo apt-get install openfoam2412-default

This installs OpenFOAM along with all required dependencies.

Step 5: Start OpenFOAM environment

openfoam2412

This launches a shell with the OpenFOAM environment configured.

You can verify installation by running:

foamVersion

Installing Other Versions

The same process applies to other OpenFOAM versions. Only the package name changes.

For example:

sudo apt-get install openfoam2306-default
sudo apt-get install openfoam2212-default

Method 2: Installing OpenFOAM using Docker

Docker allows OpenFOAM to run inside containers. This avoids dependency issues and ensures a consistent environment across systems.

This method is especially useful for:

  • Portable workflows
  • Teaching environments
  • Cloud computing
  • Avoiding system conflicts

Step 1: Install Docker

Follow official Docker installation guide: https://docs.docker.com/engine/install/ubuntu/

We will install Docker using the APT repository method.

Step 2: Setup Docker repository

sudo apt update
sudo apt install ca-certificates curl

sudo install -m 0755 -d /etc/apt/keyrings

sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
-o /etc/apt/keyrings/docker.asc

sudo chmod a+r /etc/apt/keyrings/docker.asc

Add Docker repository:

sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF

Update packages:

sudo apt update

Step 3: Install Docker

sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Step 4: Verify Docker installation

sudo docker run hello-world

Step 5: Run OpenFOAM container

You can run OpenFOAM directly using a container.

Example:

docker pull pawannegi/openfoam24-cfmesh:latest

docker run -it -v localfolder:/run pawannegi/openfoam24-cfmesh:latest

This mounts your local folder into the container at /run

Alternative: Using official OpenFOAM Docker script

Download the script:

https://gitlab.com/openfoam/packaging/containers/-/raw/main/openfoam-docker

Rename it:

mv openfoam-docker openfoam-docker.sh
chmod +x openfoam-docker.sh

Run OpenFOAM:

./openfoam-docker.sh

More details are available here:

https://gitlab.com/openfoam/core/openfoam/-/wikis/precompiled/docker#running-openfoam-in-a-container

Method 3: Installing OpenFOAM from Source

This method gives full control over compilation and customization. It is recommended for:

  • Developers
  • Researchers modifying solvers
  • Advanced users

Step 1: Install dependencies

sudo apt-get update

sudo apt-get install build-essential flex bison \
cmake zlib1g-dev libboost-system-dev \
libboost-thread-dev libopenmpi-dev openmpi-bin \
gnuplot libreadline-dev libncurses-dev libxt-dev

Install Qt5 dependencies (Qt4 is deprecated):

sudo apt install qtbase5-dev qtchooser qttools5-dev-tools

sudo apt install libqt5opengl5-dev

sudo apt install libqt5webkit5-dev

Step 2: Download source code

Download OpenFOAM v2412 and ThirdParty packages from:

https://gitlab.com/openfoam/core/openfoam/-/tree/maintenance-v2412

Specific requirements:

https://gitlab.com/openfoam/core/openfoam/-/blob/maintenance-v2412/doc/Requirements.md

Build instructions:

https://gitlab.com/openfoam/core/openfoam/-/blob/maintenance-v2412/doc/Build.md

Step 3: Configure environment

source <installation path>/OpenFOAM-v2412/etc/bashrc

Step 4: Compile ThirdParty

cd ThirdParty-v2412
./Allwmake -j8

Step 5: Compile OpenFOAM

cd OpenFOAM-v2412
./Allwmake -j8

The -j8 option uses 8 CPU cores. Adjust based on your system.

Example:

./Allwmake -j4

Which Installation Method Should You Choose?

MethodDifficultyRecommended for
APTEasyMost users
DockerMediumPortable workflows
SourceAdvancedDevelopers and researchers

Verifying Installation

Run:

foamVersion

You should see:

OpenFOAM-v2412

You can also run a tutorial case:

cd $FOAM_TUTORIALS

Free Course: Complete OpenFOAM Installation Guide

To make installation easier, we provide a free course covering OpenFOAM installation on Ubuntu and Windows.

This course includes:

  • Installing OpenFOAM v2412 using APT, Docker, and Source
  • Installing ParaView for visualization
  • Setting up WSL for Windows users
  • Running tutorial cases
  • Understanding OpenFOAM directory structure
  • Configuring Visual Studio Code
  • Running and visualizing simulations

Access the free course here:

Conclusion

OpenFOAM provides flexible installation methods to suit different needs.

For most users, the APT method is recommended because it is simple and reliable.

Docker provides portability and reproducibility, while compiling from source gives maximum control.

Regardless of the method used, once OpenFOAM is installed correctly, you can focus entirely on learning CFD, running simulations, and exploring solver internals.