In this post you will learn how to install OpenFOAM v1912 from source pack. The operating system is ubuntu 18.04 LTS. It is assumed that you are installing OpenFOAM v1912 on a fresh operating system.
A) Download and Initial Checks
1) Downloading source code: go to official website of OpenFOAM v1912 and download the source pack of the latest version (at the moment it is OpenFOAM v1912). Or simply follow these links to download the compressed files by clicking on them:
2) Creating installation folder in the home folder: move the downloaded compressed files to the directory in which you want to install (compile) OpenFOAM v1912. 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:
tar -xzf OpenFOAM-v1912.tgz tar -xzf ThirdParty-v1912.tgz
Two folders with names “OpenFOAM-v1912” and “ThirdParty-v1912” are created under ~/OpenFOAM folder.
4) Compiler version: check the compiler version. You need gcc version 4.8 or higher.
gcc --version
if you do not have gcc installed on your computer or gcc version is lower than 4.8, execute the following commands:
sudo apt-get update sudo apt-get install gcc
B) Installing prerequisites on your Computer
5) Installing prerequisites: you need to install other packages to be able to compile and run OpenFoam and Paraview. These packages are FLEX, cmake, Git distributed version control, and OpenMPI and etc. To install these packages on Ubuntu 18.04, execute the following commands in the terminal (for compiling and running OpenFOAM):
sudo apt-get update 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
In any stage of package installation, if you get error “unable to fetch some archives”, try the following command:
sudo apt-get update --fix-missing
and restart installing packages.
6) Setting environmental variables: in this step, you need to set environmental variables. The method allows you to install multiple versions of OpenFOAM v1912 on your computer at the same time. So, 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 v1912 in the $HOME/OpenFOAM directory).
alias of1912="source $HOME/OpenFOAM/OpenFOAM-v1912/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:
of1912
C) Compiling and running
7) Installing Third-party packages: change the current directory to $HOME/OpenFOAM/ThirdParty-v1912 in the terminal (you already entered of1912 command in this terminal) and then enter this command to install third party packages:
./Allwmake
8) Compiling OpenFOAM: change the current directory to $HOME/OpenFOAM/OpenFOAM-v1912 in the terminal (you already entered of1912 command in this terminal) and then enter this command to compile OpenFOAM:
./Allwmake -j
this may take several minutes to hours to finish.
9) using OpenFOAM: you will find some tutorials on using OpenFOAM v1912 on this website and cfd.at.
Hello, thank’s for sharing this tutorial, but i have problem when i try to compile Paraview in thirdParty folder
We did not install any third-party packages from its source file (in ThirdParty-v1912 folder), since all the required packages for building OpenFoam was already installed in step 5. My recommendation is to install the binary distribution of ParaView (https://www.paraview.org/download) rather than building it from source since it is hard.
Building from source pack requires changing some shell variables, downloading and installing Qt on your computer and etc. In addition, the building process may takes several minuets to complete.
Hello, I followed the instructions step by step and indeed OF has been installed and worked as expected. However, when I restart my pc OF vanishes!!!! It happened twice so far. I cannot find anything online. Do you know the reason maybe? Thanks in advance.
Hi, did you execute the below command after opening a new terminal (or after computer restart), when you want to use openFoam?
> of1912
this command will read the baschrc of openfoam and loads all he env. variables into the terminal’s. You must always enter this command every time you open a new terminal.
Oh, I didn’t know that I have to execute this command every time I open a new terminal. I switched back to the Foundation version now. Anyway, thanks a lot for the prompt reply.
You can see in this post (https://www.cemf.ir/how-to-install-openfoam-from-source-pack/) how to install the foundation version along-side the v1912. You’re welcome. Remember that you can have multiple version of openfoam installed on your computer and load one of them whenever you want.