How to build OpenFOAM on M1 MAC

Jun OKAMURA
2 min readFeb 23, 2022

This is a short note about how to build OpenFOAM from the source by using the Docker image on my M1 MAC (Monterey on Macbook Air M1–2020) environment.

Preparation

Docker has been supported Apple silicon chip already, then install Docker by the following link;
https://docs.docker.com/desktop/mac/apple-silicon/

Download Dockerfiles and build the image

To build a proper Dockerfile which can work natively on Apple-silicon, download the container package files from the following Github repository;
https://develop.openfoam.com/packaging/containers
Edit build_leap.Dockerfile and add “vim” to edit files

% cd containers-main/docker
% docker build -t opencfd/openfoam-build -f build_leap.Dockerfile .

Run docker image with bash

Download OpenFOAM source files and extract them into the Docker.

% docker run --rm -it opencfd/openfoam-build bash$ mkdir OpenFOAM
$ wget https://dl.openfoam.com/source/v2112/OpenFOAM-v2112.tgz .
$ wget https://dl.openfoam.com/source/v2112/ThirdParty-v2112.tgz .
$ tar zxvf OpenFOAM-v2112.tgz -C OpenFOAM/
$ tar zxvf ThirdParty-v2112.tgz -C OpenFOAM/

Edit etc/bashrc by vim

$ cd OpenFOAM/OpenFOAM-v2112
$ diff etc/bashrc etc/bashrc.orig
98,99c98
< #export WM_MPLIB=SYSTEMOPENMPI
< export WM_MPLIB=OPENMPI
---
> export WM_MPLIB=SYSTEMOPENMPI
$ souurce etc/bashrc

Build OpenFOAM

$ foam
$ ./Allwmake -j -s -q -l

Verify

$ foamInstallationTest

Enjoy!!!

--

--