How to install OpenFOAM-9

In this tutorial, you will learn how to install OpenFOAM-9. If you already have some components installed on your computer, you may skip some of the steps. This tutorial has been tested on Ubuntu 18.04 LTS, Ubuntu 20.04 LTS, and Ubuntu 22.04 LTS. Two main methods is introduced here: 1) source pack and 2) pre-built files.

1) Installing OpenFOAM-9 from source pack  

A) Download and Initial Checks

1-1) Downloading source code: go to official website of OpenFOAM and download the latest version (at the moment it is OpenFOAM 7). Or simply follow these links to download the compressed files.

1-2) Creating installation folder in the home folder: move the downloaded compressed files to the directory in which you want to install (compile) OpenFOAM. Here we keep everything on the home folder of the computer. Create a new folder with name “OpenFOAM” on the home folder and moved the compressed files into this folder.

1-3) Unpacking the files: open a new terminal in this folder and decompress these two files with these commands:

tar -xzf ThirdParty-9-version-9.tar.gz 
tar -xzf OpenFOAM-9-version-9.tar.gz

1-4) Renaming: rename the folders using the following commands in the terminal (or manually using GUI):

mv OpenFOAM-9-version-9 OpenFOAM-9 
mv ThirdParty-9-version-9 ThirdParty-9

1-5) Compiler version: check the compiler version. You need gcc version 5.4 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:

gedit ~/.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 of90="source $HOME/OpenFOAM/OpenFOAM-9/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:

of90

C) Compiling and running

1-8) Installing Third-party packages: change the current directory to $HOME/OpenFOAM/ThirdParty-9 in the terminal (note that you already entered of90 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-9 in the terminal (note that you already entered of90 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-9 from pre-built files  

This method of installation will install OpenFOAM-9 and Paraview v5.6.3 on your computer in /opt directory. This version of OpenFOAM can be installed on Ubuntu 18.04 LTS, or higher LTS versions.

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 openfoam9

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 of90="source /opt/openfoam9/etc/bashrc"

2-5) Testing: Enter the following commands in a new terminal, if it outputs the help lines, every thing is working properly.

of90
simpleFoam -help

Leave a Reply

Your email address will not be published. Required fields are marked *