How to install OpenFOAM 7 from source pack

In this tutorial, you will learn how to install OpenFOAM-7 from source pack. If you already have some components installed on your computer, you may skip some of the steps. This tutorial has been tested on Ubuntu 16.04 LTS, Ubuntu 18.04 LTS, and Ubuntu 20.04 LTS.

A) Download and Initial Checks

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.

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.

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

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

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

mv OpenFOAM-7-version-7 OpenFOAM-7
mv ThirdParty-7-version-7 ThirdParty-7

5) Compiler version: check the compiler version. You need gcc version 4.8 or higher.

gcc --version

B) Installing prerequisites on your Computer

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, execute the following commands in the terminal (for compiling and running OpenFOAM):

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

and the following commands (for Paraview):

sudo apt-get install libqt5x11extras5-dev libxt-dev qt5-default qttools5-dev curl

7) Setting environmental variables: in this step, you need to set environmental 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 of70="source $HOME/OpenFOAM/OpenFOAM-7/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:

C) Compiling and running

8) Installing Third-party packages: change the current directory to $HOME/OpenFOAM/ThirdParty-7 in the terminal (you already entered of70 command in this terminal) and then enter this command to install third party packages:


and then enter the following command to install Paraview. You need internet connection for this step.


9) Compiling OpenFOAM: change the current directory to $HOME/OpenFOAM/OpenFOAM-7 in the terminal (you already entered of70 command in this terminal) and then enter this command to compile OpenFOAM:

./Allwmake -j

this may take several minutes to hours to finish compilation.

10) Testing OpenFOAM: follow the instructions in one of the tutorials on this page.



2 Feedbacks on “How to install OpenFOAM 7 from source pack”

Leave a Reply

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