We are suggesting two methods for installing OpenFOAM-12 on ubuntu and windows: 1) source pack and 2) pre-built files. If you already have some components installed on your computer, you may skip some of the steps. This method has been tested on Ubuntu 20.04 LTS, Ubuntu 22.04 LTS, and Ubuntu 24.04 LTS. Installing from source-pack gives you more flexibility to install OpenFOAM on other distributions of Ubuntu and also older versions of Ubuntu.
Installing of Windows first involves installing wsl2 on your Windows OS and then following the instructions given here for installing OpenFOAM. To see how you can install wsl2 and Ubuntu on your windows OS, see this page. So, after installing these components on your computer, get back here and choose one of these methods to install OpenFOAM-12.
1) Installing OpenFOAM-12 from source pack
A) Download and Initial Checks
1-1) Creating installation folder in the home folder (if you have not created it before): go to your home directory on the operating system and make a new directory with name OpenFOAM and under this directory open a new terminal to start the process of installation. You can do all of these steps through terminal too. For this, open a new terminal and execute these commands:
cd ~ mkdir OpenFOAM cd OpenFOAM
1-2) Downloading source code: use these commands to download the source code and extract them in the OpenFOAM folder that you just created:
wget -O - http://dl.openfoam.org/source/12 | tar xvz wget -O - http://dl.openfoam.org/third-party/12 | tar xvz
1-3) Renaming: rename the folders (the unpacked source code) using the following commands in the terminal (or manually using GUI):
mv OpenFOAM-12-version-12 OpenFOAM-12 mv ThirdParty-12-version-12 ThirdParty-12
1-5) Compiler version: check the compiler version. You need gcc version 5.5 or higher.
gcc --version
B) Installing prerequisites on your Computer
1-6) Installing prerequisites: you need to install other packages to be able to compile and run OpenFoam and Paraview. These packages are FLEX, cmake, QT, Git distributed version control, and OpenMPI. To install these packages on Ubuntu 18.04 or above versions, execute the following commands in the terminal (for compiling and running OpenFOAM):
sudo apt-get install build-essential cmake git ca-certificates sudo apt-get install flex libfl-dev bison zlib1g-dev libboost-system-dev libboost-thread-dev libopenmpi-dev openmpi-bin gnuplot libreadline-dev libncurses-dev libxt-dev
1-7) Setting environment variables: in this step, you need to set environment variables. The method which is suggested here will enable you to install multiple versions of OpenFOAM on your computer at the same time. Open ~/.bashrc file using this command:
nano ~/.bashrc
and add the following line at the end of this file, save and close the file (assuming that you installed OpenFOAM in the $HOME/OpenFOAM directory).
alias of12="source $HOME/OpenFOAM/OpenFOAM-12/etc/bashrc"
then enter this commands in the current terminal window:
source ~/.bashrc
the bashrc file of OpenFoam which contains the environmental setting is not configured in the current terminal window. To load these settings into the current terminal window (or any new terminal window that you open) you need to enter the following command:
of12
C) Compiling and running
1-8) Installing Third-party packages: change the current directory to $HOME/OpenFOAM/ThirdParty-12 in the terminal (note that you already entered of12 command in this terminal) and then enter this command to install third party packages:
./Allwmake
1-9) Compiling OpenFOAM: change the current directory to $HOME/OpenFOAM/OpenFOAM-12 in the terminal (note that you already entered of12 command in this terminal) and then enter this command to compile OpenFOAM:
./Allwmake -j
this may take several minutes to hours to finish compilation.
1-10) Testing OpenFOAM: follow the instructions in one of the tutorials on this page and also OpenFOAM tutorials.
2) Installing OpenFOAM-12 from pre-built files
This method of installation will install OpenFOAM-12 and Paraview on your computer in /opt directory. This version of OpenFOAM can be installed on Ubuntu 20.04 LTS, 22.04 and 24.04.
2-1) Adding OpenFOAM to apt: Enter the following commands in the terminal to add OpenFOAM repository to the search list of apt and public key gpg for verification:
sudo sh -c "wget -O - https://dl.openfoam.org/gpg.key > /etc/apt/trusted.gpg.d/openfoam.asc" sudo add-apt-repository http://dl.openfoam.org/ubuntu
2-2) Update the apt package:
sudo apt-get update
2-3) Install OpenFOAM and Paraview:
sudo apt-get -y install openfoam12
2-4) Setting environment variables: You should add the following line to the end of your ~/.bashrc file to allow the system find OpenFOAM installation on your computer. Enter the following command:
gedit ~/.bashrc
and then add the following line to the end of that file, save and close it.
alias of12="source /opt/openfoam12/etc/bashrc"
2-5) Testing: Enter the following commands in a new terminal, if it outputs the help lines, every thing is working properly.
of12 foamRun -help