In this post you will learn how to install OpenFOAM v2006 from source pack. The operating system is Ubuntu 18.04 LTS. It is assumed that you are installing OpenFOAM v2006 on a fresh operating system. The steps to be followed for installing OpenFOAM v2006 on Ubuntu 20.04 LTS should be essentially the same, although we did not explicitly tested it.
Note: If you previously installed the older version of OpenFOAM from source pack, you may not need to install some of the prerequisite packages on your computer and skip them.
You can find instructions to install older versions of OpenFOAM:
A) Download and Initial Checks
1) Downloading source code: go to official website of OpenFOAM v2006 and download the source pack of the latest version (at the moment it is OpenFOAM v2006). 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 v2006. Here we keep everything on the home folder of the computer. Create a new folder with name “OpenFOAM” (if you already do not have it) 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-v2006.tgz tar -xzf ThirdParty-v2006.tgz
Two folders with names “OpenFOAM-v2006” and “ThirdParty-v2006” are created under ~/OpenFOAM folder.
4) Compiler version: check the compiler version. You need gcc version 4.8.5 or higher.
if you do not have gcc installed on your computer or gcc version is lower than 4.8.5, 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 , boost, 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 autoconf autotools-dev cmake gawk gnuplot sudo apt-get install flex libfl-dev libreadline-dev zlib1g-dev openmpi-bin libopenmpi-dev mpi-default-bin mpi-default-dev sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev sudo apt-get install libscotch-dev libptscotch-dev libfftw3-dev libboost-system-dev libboost-thread-dev libcgal-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 v2006 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 v2006 in the $HOME/OpenFOAM directory).
alias of2006="source $HOME/OpenFOAM/OpenFOAM-v2006/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-v2006 in the terminal (you already entered of2006 command in this terminal) and then enter this command to install third party packages:
Note: Most of the third-party packages are already installed on your computer by executing commands in step 6. OpenFOAM, by default, uses some packages that are installed on your system (from git repository) and the rest from your third-party folder. So, if you successfully installed all the required packages on your system from git repository (step 6), you would not need to build (re-install) them from third-party folder.
8) Compiling OpenFOAM: change the current directory to $HOME/OpenFOAM/OpenFOAM-v2006 in the terminal (you already entered of2006 command in this terminal) and then enter this command to compile OpenFOAM:
this may take several minutes to hours to finish.
Note: The above command builds OpenFOAM using all the available processors on your computer. If you do not have enough RAM and/or Swap space, compilation may fail due to shortage of memory. In this case, just remove -j flag from above command.