OpenFOAM for Windows

The packaged distributions of OpenFOAM for Ubuntu can now be installed directly on Microsoft Windows 10 using Windows Subsystem for Linux (WSL).  WSL provides a full compatibility layer for running Linux applications on Windows by performing real-time translation of Linux system calls into Windows OS system calls.  The system can support graphical Linux applications, such as the version of ParaView that includes the OpenFOAM reader module, with additional X server software (see below).  Running OpenFOAM applications in parallel using WSL is reported to work effectively.

Note: We do not support older versions of Windows, e.g. 7 or 8, because Microsoft does not support them.

Activate Windows Subsystem for Linux

  • Follow the Guide to Install WSL and install the Ubuntu 20.04 LTS Linux Distribution.
  • Make a note of the WSL version you are running, either v1 or v2.
  • Launch the Ubuntu distribution through WSL.

Installing OpenFOAM

The packaged distributions of OpenFOAM on Ubuntu Linux can now be installed from within the Bash environment.  We recommend users install the Ubuntu pack of the latest version of OpenFOAM (currently v11) or the current development version (or both).

  • Installing OpenFOAM 11
    sudo sh -c "wget -O - | apt-key add -"
    sudo add-apt-repository
    sudo apt-get update
    sudo apt-get install openfoam11
  • Installing OpenFOAM-dev
    sudo sh -c "wget -O - | apt-key add -"
    sudo add-apt-repository " dev"
    sudo apt-get update
    sudo apt-get install openfoam-dev

Compilation Tools

In order to compile applications and libraries in OpenFOAM, the user should install additional compilation tools by the following command:

sudo apt-get install build-essential

User Configuration

In order to use the installed OpenFOAM package, the user needs to set their environment for OpenFOAM as follows.

  1. One Time Only: At the bottom of the user’s .bashrc file, source the bashrc file in the OpenFOAM installation which contains the environment settings.  For openfoam11, the following command avoids the need to open an editor (for OpenFOAM-dev, replace openfoam11 with openfoam-dev):
    echo ". /opt/openfoam11/etc/bashrc" >> $HOME/.bashrc
  2. One Time Only: register the change to the .bashrc file by typing at the terminal prompt (note the dots):
    . $HOME/.bashrc
  3. Test that the simpleFoam application, from the OpenFOAM package, is working by typing
    simpleFoam -help
  4. A “Usage” message should appear. Your installation and user configuration is complete.

If more than one OpenFOAM package is installed, e.g. both openfoam11 and openfoam-dev, the user’s .bashrc file should contain only the source... command for the version they currently wish to use.

Enabling Graphical Applications

To run graphical Linux applications, such as ParaView or the gedit editor, requires the installation of X server software.  The most popular X server software for Windows is VcXsrv, which can be installed as described below.

  • Download the VcXsrv installer.
  • (if the above link does not work, go to the VcXsrv files page and download the latest vcxsrv-64.X.X.X.X.installer.exe file).
  • Run XLaunch that was installed by VcXsrv.
  • Open the “Extra settings” window and: a) Deselect (uncheck) “Native opengl”; b) Select “Disable access control”.

When a bash shell is opened, the DISPLAY environment variable needs to point to the X server that is running.  To make this addition permanent, set the DISPLAY in the user’s .bashrc file by the following command:

  • for WSL v1
    echo "export DISPLAY=:0" >> ${HOME}/.bashrc
  • for WSL v2
    echo "export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0" >> ${HOME}/.bashrc

Source the .bashrc file again, i.e. execute one time only:

. $HOME/.bashrc

With graphics enabled, users may wish to install other useful supporting graphical applications for OpenFOAM, such as the gedit file editor, the GnuPlot graph drawing package, and mplayer video player (and mencoder encoder) software, e.g.

sudo apt-get install gedit gedit-plugins
sudo apt-get install gnuplot gnuplot-x11 gnuplot-doc libgd-tools
sudo apt-get install mplayer mencoder

Problem running ParaView

Try to start ParaView from a terminal by typing:


There is a bug in WSL v1 only which may cause ParaView to fail to open with the message:

/opt/paraviewopenfoam510/lib/paraview: error while loading shared libraries: 
cannot open shared object file: No such file or directory

If this occurs, enter the following commands (copy/paste) in the terminal:

sudo cp /usr/lib/x86_64-linux-gnu/ /opt/paraviewopenfoam510/mesa/lib/
sudo strip --remove-section=.note.ABI-tag /opt/paraviewopenfoam510/mesa/lib/

Next Steps

See OpenFOAM on Ubuntu: Getting Started.  If the user has enabled graphical applications, they can open the gedit editor in the background (&) with

gedit &

Otherwise without graphical support, 3 popular editors which can work through a terminal are:

  • nano: the easiest of the 3 editors for the purpose, see nano basics guide;
  • emacs: powerful editor that uses a more complex set of key commands, emacs basics;
  • vim: another editor with arguably a less familiar set of key commands, see vim quick guide.

It is worth knowing the command to exit the editor you use in case a problem arises:

  • nano exits with C-x (C=Control key)
  • emacs exits with C-x C-c (preceded by C-g, if needed)
  • vim exits with ESC :q!