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.
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:
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:
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
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:
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:
this may take several minutes to hours to finish.