Installing OpenFOAM 2.2.0 on Mac OS X Mountain Lion (10.8.3)

March 31st, 2013 | Posted by admin in Installation | OpenFOAM


In this quick guide, we will show you how to install OpenFOAM 2.2.0 on Mac OS X 10.8.3, as known as Mountain Lion.

This post is only a repetition of awesome work by B. Gschaider, and the original link can be found here.


A. Prerequisite

First, we need to make sure we have all the required files before installing OpenFOAM.

1. Xcode | https://developer.apple.com/xcode/

  • Download the latest version of Xcode and Command Line Tools. You’re going to need an Apple ID, and probably need to register as a developer. We’re using Xcode 4.6.1, and Command Line Tools  (OS X Mountain Lion) for Xcode – March 2013

2. MacPorts | http://www.macports.org/

  • Download Macports for Mountain Lion, and installation should be very straightforward (.pkg file)


B. Compilers and Libraries

Gcc4.6, OpenMPI, flex, bison, boost, cgal, ccache
(there was a mistake when I recorded the video. It’s ccache, not cache)

Now you’re ready to use MacPorts to install compilers and libraries using MacPorts. Simply launch Terminal and enter following commands.

sudo port selfupdate
Check if we’re on the same page.
gcc --version
If it returns default GCC 4.2.1, you’ve installed Xcode correctly. Recent updates in OpenFOAM require GCC 4.5 or higher. We’ll use MacPorts to install GCC 4.6
sudo port install gcc46
Select Gcc 4.6 as default compiler by typing the following.
sudo port select gcc mp-gcc46

Check to see if you’re doing it correct so far.

>> gcc –version
gcc (MacPorts gcc46 4.6.3_9) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO

Now install OpenMPI by typing
sudo port install openmpi

These two will take a while, so sit back, and try not to scare your computer. You can also install multiple tools using a single command. Try this line to install the remainder.
sudo port install flex bison boost cgal ccache


 C. OpenFOAM

Option 1 : Download precompiled sparseimage file.

1. Unzip, and double-click the .sparseimage file to mount
2. Create symbolic link on your home directory.
cd ~
ln -s /Volumes/OpenFOAM-v2.2 OpenFOAM

3. Edit your .profile to source ~/OpenFOAM/OpenFOAM-2.2.0/etc/bashrc when you start up Terminal
vi ~/.profile
Add this line…
source OpenFOAM/OpenFOAM-2.2.0/etc/bashrc
4. Clean and recompile OpenFOAM
cd ~/OpenFOAM/OpenFOAM-2.2.0


Option 2 : If it doesn’t work out of the box for some reason, carefully follow this instruction.


This post is not approved or endorsed by ESI Group.

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

10 Responses

  • Bruno says:


    Thanks for the tutorial. I’m currently having 2 issues:

    1 – Whenever I source OpenFOAM/OpenFOAM-2.2.0/etc/bashrc I’m getting:

    sed: 1: “s@ /Users/fletcher/.rvm …”: bad flag in substitute command: ‘D’
    sed: 1: “s@ /Users/fletcher/.rvm …”: bad flag in substitute command: ‘D’
    sed: 1: “s@ /Users/fletcher/.rvm …”: bad flag in substitute command: ‘D

    Any idea why sed does not like this?

    2- Also, I don’t have a ~/.profile file. Shouldn’t I be putting the source command in ~/.bash_profile . I tried putting it in ~/.profile, but it just does source the OpenFOAM environment variables when I reload the terminal. I’m guessing you are sourcing your ~/.profile from ~/.bash_profile.

    One last thing, for those who want to increase the image size (as ~2 GB is too small to run a larger cases):

    hdiutil resize -size 15g /pathToImage/OpenFOAM-v2.2.sparseimage

    Where /pathToImage/ is the the directory where the image is located.


    • admin says:

      Thanks for the feedback, Bruno!

      1. Do you have openmpi installed correctly? Type in which mpirun, and you should see something like /opt/local/bin/mpirun

      or $$ mpirun --version
      mpirun (Open MPI) 1.6.4
      Report bugs to http://www.open-mpi.org/community/help/

      If that’s not the case for you try linking mpirun with otrerun
      $$ cd /opt/local/bin
      $$ ln -s /opt/local/lib/openmpi/bin/orterun mpirun

      2. I don’t really have .bash_profile on my home folder. If you don’t have .profile, I’d suggest you to make one. Here’s how mine looks like.
      alias ls='ls -G'
      export CLICOLOR=1
      export LSCOLORS=ExFxBxDxCxegedabagacad
      # Your previous /Users/shaun/.profile file was backed up as /Users/shaun/.profile.macports-saved_2013-03-27_at_00:39:06
      # MacPorts Installer addition on 2013-03-27_at_00:39:06: adding an appropriate PATH variable for use with MacPorts.
      export PATH=/opt/local/bin:/opt/local/sbin:$PATH
      # Finished adapting your PATH environment variable for use with MacPorts.

      source OpenFOAM/OpenFOAM-2.2.0/etc/bashrc

      3. Thanks for the tip to increase the image size on terminal! I always make a separate folder on my home folder named “RUN” and do all the calculation outside the image drive.


  • ricardo says:

    Some questions…

    The command sudo port upgrade outdated is necessary? What it does exactly?

    The gschaider post you cited say some configs to bashrc file:

    Contents of my ../site/2.2.x/prefs.sh are:
    export WM_COMPILER=Gcc46
    export WM_SCHEDULER=ccache

    On this other tutorial: http://openfoamwiki.net/index.php/Howto_install_OpenFOAM_v21_Mac
    Also says about some configs:

    export WM_COMPILER=Gcc46
    ulimit −n 1024
    export WM_NCOMPPROCS=4 -> sysctl -n hw.ncpu
    export WM_CC=’gcc-mp-4.6′
    export WM_CXX=’g++-mp-4.6′

    Is necessary to do this after or before compiling? As I have a quad core i7 with 4 cores and 8 threats if i set 8 will increase my computational speed?

    And after compiling, when trying to use paraFoam on cavity tutorial I had an error on paraView saying me to do this:

    cd $FOAM_UTILITIES/postProcessing/graphics/PV3Readers

    Do you have any idea?
    Cheers, very nice job.

    • Bruno says:


      Thanks for the reply a couple of weeks ago. I tried to say thanks through this form 24 hrs after your reply but the message never went through. I’ve figured out the issue was on my side. RVM (Ruby-related) was set as an old environment variable for a script that had been deleted from my machine (I had removed Brew prior to installing macports following your tutorial). Perhaps my next trip to Austin I should get a case of beer to thank you!

      Ricardo, 3rd party does not seem to be installed. Just download paraview from the the kitware website. To load an openFoam case in paraview, just create a dummy file called “case.foam” at the base directory of your simulation, and load in paraview (File->Open).


      Bruno – Boulder, CO

      • admin says:

        Thanks for your kind words and some wisdom, Bruno!
        I do the same thing for Paraview. I create a dummy file by typing touch case.foam in the working folder, and open it from Paraview.


  • Kiarash says:

    Hello Admin,
    I did every step like mentioned without any problem but my openFOAM doesn’t work. spite installing macports, when I start my terminal I get the following message :
    “Seems you’re not using MacPorts. This is currently not supported/tested. Find this line in ‘etc/config/settings.sh’, modify it accordingly and send patches to Bernhard”
    I thought maybe that has sth to do with not working. As a matter of fact I had installed the previous version (2.0.x) with your last video, and I wanted to upgrade it, so I installed Mountain Lion to upgrade but it doesn’t work anymore. what should I do?
    best regards

  • Laura VDW says:


    I was just wondering if this works also for Mac OSX 10.6.8 (Snow Leopard). I want to be sure before I try…

    Grtz, Laura

  • Amadeo says:

    Hi Admin,

    Firstly thanks for de tutorial and precompiled image.

    I’m using it and I think that I find a bug that is the next one:

    When I try to use “simpleSpline” I get the next error:
    Unknown curvedEdge type simpleSpline

    Valid curvedEdge types are


    From function curvedEdge::New(const pointField&, Istream&)
    in file curvedEdges/curvedEdge.C at line 96.

    FOAM aborting

    #0 Foam::backtrace(void**, unsigned int) in “/Users/amadeomoranguerrero/OpenFOAM/ OpenFOAM-2.2.0/platforms/darwinIntel64GccDPOpt/lib/libOpenFOAM.dylib”
    Segmentation fault: 11

    I found that there are the same bug at OpenFOAM 1.6 and it’s occur because the file “OpenFOAM/OpenFOAM-2.2.0/applications/utilities/mesh/generation/blockMesh/Make/files” is not complete.

    I try to rewrite the file (with the official file version 1.6) and recompile but does’t work.

    Comparing the folder blockMesh at version 1.6 and 2.2 on .sparseimage they are very different. I try as well to copy this folder on .sparseimage and recompile but does’t work.

    You know anything about that? And the most important can you do a mesh with simpleSpline?
    Maybe is only my problem.

    Thanks for all

Leave a Reply

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


Please enter the CAPTCHA text