OpenFOAM on Your Own Laptop

The teaching is designed so that you should follow the steps I do on a computer. We will have access to computers with pre-installed software during the lectures, but it is highly recommended that you install the software on your own laptop so that you are independent. The Linux commands below are written for bash shell.

By following the instructions below, you should be able to install Ubuntu 12.04 LTS, OpenFOAM-2.2.x (one optimal and one debug version), OpenFOAM-1.6-ext, PyFoam, Python packages, Gnuplot etc., and later perhaps some additional useful things that we will use in the course. We will pull the git source and compile from scratch, since we will then get access to updates and bug fixes. OpenFOAM-2.2.0 can also be installed as a package, which is much faster, but gives less control in my opinion ( Feel free to try it out if you like – you can have both that version and the git versions installed at the same time!

Note that I am (unfortunately) using Word to generate this web page, which means that Word sometimes decides to change some characters to other characters that look the same, but aren’t (e.g. – is not the same as - or -- and “ is not the same as "). I think that I have fixed this everywhere, but you never know. That is one reason for copy-pasting single rows rather than multiple rows, and check that all went well. Another reason is that some lines will require you to press a key at some point, such as the “sudo apt-get” lines. Let me know if you run into problems, and I’ll help you.

Installation and updating of Ubuntu 12.04 LTS in Virtual Box (under Windows 7, in this case):


This section takes about 1.5 hour to complete.

Download Ubuntu 12.04 LTS (note that you can get it for free by setting your contribution to zero):, get Ubuntu Desktop (in my case 64 bit), save iso-file
(Optional: burn iso to CD (if you do, make sure to burn it as iso, to make the CD bootable!))

You can use VirtualBox to install Linux and OpenFOAM in your current OS. It has been recommended to use the official version downloadable from the Sun web page,, and not the pre-packed open source version, because it supports all options in an easy way (e.g. the USB controllers). See also:

After installing VirtualBox, start it and:
Create new virtual disk:
Click on New
Name: Ubuntu 12.04 LTS
Operating System: Linux
Version: Ubuntu
Base memory: 2048MB (25% of total on the machine in my case)
Create new virtual disk
Fixed size, 30GB (2GB is enough to just test one OpenFOAM installation)
Settings can be changed later, using "settings"
Click on Create

Install Ubuntu on the virtual disk:
Double-click on the virtual disk you just created
Choose installation media by browsing to the downloaded Ubuntu iso-file
Click on Install Ubuntu and choose your specific settings
I recommend that you tick: Dowload updates while installing, and Install this third-party software
When it asks you if it should erase the whole disk, it refers to the virtual disk you have just created in VirtualBox, and not your Windows disk. You should be able to see that the reported disk size is the one you requested for your virtual disk, to verify that this is correct.
Restart when asked
At the top of your Ubuntu window, there might be an icon which sais ‘Install drivers’ when you click on it. It might be good to do so, and activate virtual box drivers. I think that the scroll wheel on my mouse required this to be done.™
To the left of your Ubuntu window, there should be an icon which sais ‘Update Manager’ when you move the pointer over it. Use it to update the system, and restart Ubuntu.

Install OpenFOAM-2.2.x


This section takes about 9 hours to complete

Straight-forward according to (for 2.2.x, later in
See also:

Open a terminal window:
type (copy-paste from homepage, line-by-line):
mkdir $HOME/OpenFOAM
apt-get install git-core #requires your root password in Ubuntu and that you answer ‘y’
git clone git://

The next is a long line, starting with ‘wget’ and ending with ‘kent’. The line after that starts with ‘mv’. You may have to press Enter after it is done, to get the prompt back.
mv ThirdParty-2.2.0.tgz\?r\=http\ ThirdParty-2.2.0.tgz
tar xzf ThirdParty-2.2.0.tgz
rm ThirdParty-2.2.0.tgz
mv ThirdParty-2.2.0 ThirdParty-2.2.x

The following line is long, requires you to type your root password in Ubuntu, and type ‘y’
sudo apt-get install build-essential flex bison cmake zlib1g-dev qt4-dev-tools libqt4-dev gnuplot libreadline-dev libncurses-dev libxt-dev
#sudo apt-get install libscotch-dev libopenmpi-dev #For parallel simulations, if system versions of these are to be used. I didn't do this.
echo "alias OF22x='. $HOME/OpenFOAM/OpenFOAM-2.2.x/etc/bashrc'" >> $HOME/.bashrc

Two checks, before proceeding:
gcc --version
#Gives 4.6.3. Required: 4.5.0. Ok!
flex --version #Gives 2.5.35. Seems to have worked ok!

Close the terminal window, open a new one:
and continue:
The following line takes about 6h. You can do CTRL-C and continue later, by starting again from where you opened a new terminal window above
./Allwmake>& log_Allwmake
#Second time is fast, just to easier check the log file for possible errors - in my case none.
qmake --version #Gives 4.8.1. Required: 4.6.2 or newer. Ok!
cmake --version
#Gives 2.8.7. Required: 2.8.2 or newer. Ok!
./makeParaView #This takes 2.5h
cd $FOAM_UTILITIES/postProcessing/graphics/PV3Readers

Test the installation:
CTRL-ALT_T #To open an new terminal window
mkdir -p $FOAM_RUN
cp –r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .
cd cavity

Install OpenFOAM-2.2.x Debug version (after the above, i.e. with OpenFOAM-2.2.x installed)


This section takes about 4h to complete.

Compile Debug version, without recompiling ThirdParty:
echo "alias OF22xDebug='. $HOME/OpenFOAM/OpenFOAM-2.2.x/etc/bashrc WM_COMPILE_OPTION=Debug'" >> $HOME/.bashrc
Open new terminal window
cd $WM_THIRD_PARTY_DIR/platforms
ln -s linux64GccDPOpt linux64GccDPDebug

./Allwmake #This takes 4 hours
./Allwmake>& log_Allwmake
#Second time is fast, just to easier check the log file for possible errors - in my case none.
cd $FOAM_UTILITIES/postProcessing/graphics/PV3Readers
Don’t do wmSET since it will not pick Debug version – see alias wmSET! Instead:

Test the installation:
CTRL-ALT_T #To open an new terminal window
mkdir -p $FOAM_RUN
cp –r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .
cd cavity

Install Emacs, ddd, Python, Numpy, SciPy, Matplotlib, Gnuplot, PyFoam


This takes 10min to complete.


We will do debugging with gdb and Emacs. Emacs needs to be installed:

sudo apt-get install emacs23

You can also try ddd for debugging (not available at Chalmers):
sudo apt-get install ddd
Python-related packages
sudo apt-get install python python-dev python-matplotlib python-numpy python-scipy


sudo apt-get install gnuplot


We will follow the installation instructions for PyFoam at

Condensed installation instructions:

mkdir $HOME/OpenFOAM/linuxSrc

cd $HOME/OpenFOAM/linuxSrc


tar xzf PyFoam-0.6.1.tar.gz

rm PyFoam-0.6.1.tar.gz

cd PyFoam-0.6.1

Install as regular user (recommended):

python install --prefix=$HOME/OpenFOAM/PyFoam-0.6.1

echo "alias PF061='export PYTHONPATH=$HOME/OpenFOAM/PyFoam-0.6.1/lib/python2.7/site-packages:\$PYTHONPATH; export PATH=$HOME/OpenFOAM/PyFoam-0.6.1/bin:\$PATH'" >> $HOME/.bashrc

Open a new window and type (<TAB> refers to the tab key):




You will see numerous pyFoam commands that can be used to help you use OpenFOAM efficiently.

Install OpenFOAM-1.6-ext


OpenFOAM-1.6-ext has some features that are not in OpenFOAM-2.2.x, such as the GGI interface. If you do not need those features, you do not have to follow this section.


This section takes about 5h to complete


See also:


We will use the system installation of OpenMPI, Qt and Paraview (there are issues with the paraFoam OpenFOAM-1.6-ext reader).

Open new terminal window and type
sudo apt-get install git flex bison rpm g++ zlib1g-dev binutils-dev openmpi-bin libopenmpi-dev libxext-dev libxt-dev libxrender-dev libgl1-mesa-dev libglu1-mesa-dev
libqt4-dev qt4-dev-tools paraview
sudo ln -s /usr/bin/make /usr/bin/gmake
#gmake is the same as make, but missing in Ubuntu

git clone git:// OpenFOAM-1.6-ext
cp OpenFOAM-1.6-ext/etc/ OpenFOAM-1.6-ext/etc/
# Make the sourcing less chatty:
sed -i s/"FOAM_VERBOSE=1"/"FOAM_VERBOSE="/g OpenFOAM-1.6-ext/etc/
# Use the system installation of OpenMPI
sed -i s/"#export WM_MPLIB=SYSTEMOPENMPI"/"export WM_MPLIB=SYSTEMOPENMPI"/g OpenFOAM-1.6-ext/etc/
sed -i s/"#export OPENMPI_DIR=path_to_system_installed_openmpi"/"export OPENMPI_DIR=\/usr"/g OpenFOAM-1.6-ext/etc/
sed -i s/"#export OPENMPI_BIN_DIR=\$OPENMPI_DIR\/bin"/"export OPENMPI_BIN_DIR=\$OPENMPI_DIR\/bin"/g OpenFOAM-1.6-ext/etc/
#Tell the compiler to use the number of cores you have available (uncomment the line and change the number 4 to what you have)
#echo "export WM_NCOMPPROCS=4" >> OpenFOAM-1.6-ext/etc/
#Use the system installation of Qt
sed -i s/"#export QT_DIR=path_to_system_installed_qt"/"export QT_DIR=\/usr"/g OpenFOAM-1.6-ext/etc/
sed -i s/"#export QT_BIN_DIR=\$QT_DIR\/bin"/"export QT_BIN_DIR=\$QT_DIR\/bin"/g OpenFOAM-1.6-ext/etc/
#Use the system installation of paraview
sed -i s/"#export PARAVIEW_SYSTEM=1"/"export PARAVIEW_SYSTEM=1"/g OpenFOAM-1.6-ext/etc/
sed -i s/"#export PARAVIEW_DIR=path_to_system_installed_paraview"/"export PARAVIEW_DIR=\/usr "/g OpenFOAM-1.6-ext/etc/
sed -i s/"#export PARAVIEW_BIN_DIR=\$PARAVIEW_DIR\/bin"/"export PARAVIEW_BIN_DIR=\$PARAVIEW_DIR\/bin"/g OpenFOAM-1.6-ext/etc/

sed -i -e 's=\.OpenFOAM=\.foam=' OpenFOAM-1.6-ext/bin/paraFoam
Prepare setting up the OpenFOAM-1.6-ext environment:
echo "alias OF16ext='. \$HOME/OpenFOAM/OpenFOAM-1.6-ext/etc/bashrc'" >> $HOME/.bashrc

Open a new terminal window and type
Hint: You now have various installation instructions in $WM_PROJECT_DIR/doc/buildInstructions

We compile in steps since we don’t want OpenMPI, Qt and Paraview to be compiled (takes about 1h in total):
./AllMake.stage1 >& log.AllMake.stage1
 #Probably not needed, but I did it. (cmake, used when compiling Paraview)

#./AllMake.stage2 >& log.AllMake.stage2   # No need for this one (OpenMPI)

./AllMake.stage3 >& log.AllMake.stage3

#./AllMake.stage4 >& log.AllMake.stage4  #No need for this one (Qt and Paraview)
Run each of those lines once more just to check the log file for errors, none in my case (" already installed" on all packages)
Open a new terminal window and type OF16ext, to make sure that all new installations are recognized.
Hint: Have a look inside the AllMake.stage? files to see what they do! They give you hints on how to install additional packages.
# Update your OpenFOAM environment to get the basic configuration from the newly

# compiled ThirdParty packages

Open a new terminal window and type


./Allwmake #This takes 5 hours
./Allwmake >& log_Allwmake
#Second time is fast, just to check the log file for errors, none in my case

Test the installation:
CTRL-ALT_T #To open an new terminal window
mkdir -p $FOAM_RUN
cp –r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .
cd cavity

When running paraFoam you will get some messages in the terminal window and in a pop-up-window. Just move that pop-up-window out of sight and ignore the messages.

Note also that we are here using the OpenFOAM reader distributed with Paraview, which is slightly different from the one distributed with OpenFOAM. I was not able to make the one distributed with OpenFOAM-1.6-ext work.