How to run FreeSurfer on Windows with WSL2

FreeSurfer is an open source software suite for processing and analyzing (human) brain MRI images. It has tons of features, including skullstripping, subcortical and cortical segmentation, cortical surface reconstruction, and more.

FreeSurfer pipeline
Grossner et al. (2018). doi: 10.1037/neu0000446.

Currently (as in version 7.1.1), Freesurfer is available only for the Linux and Mac OS X operating systems. You can run FreeSurfer in Windows using a virtual machine, but that can slow down the processing a little. One alternative is to use Windows Subsystem for Linux. Here I’ll show, based on the official FreeSurfer documentation, the steps to install WSL and setup FreeSurfer (including running the graphical user interface).

What is WSL

The Windows Subsystem for Linux (WSL) lets developers run a GNU/Linux environment – including most command-line tools, utilities, and applications – directly on Windows, unmodified, without the overhead of a traditional virtual machine or dual-boot setup. - Docs

Steps

1. Install WSL2

Follow the steps from 1 - 6 from the Microsoft documentation. Please select the Ubuntu 18.04 LTS version (step 6).

2. Install an X-server to open the graphical user interface (GUI)

Full WSL support for GUI apps will be available in the future, probably in the next major Windows release. In the meantime, we must use an X-server to render the GUI. There are many options, but I recommend two:

GWSL

GWSL is a free and easy to install tool to automate the process of running X on top of WSL. You can obtain it in the Microsoft Store.

Xming

Xming server is the one described in the FreeSurfer documentation.

3. Get a FreeSurfer license key

Register for a FreeSurfer key. Totally free.

4. Install FreeSurfer

Now, open your Ubuntu terminal installed with WSL and follow the FreeSurfer installation steps or use the automated script below. Please note that the FreeSurfer guide installs a dev version, so you should probably change that to a stable distribution (like v7.1.1 for CentOS 7).

Installation script

The script will download and install FreeSurfer version 7.1.1 released for CentOS 7. It will also set the environment variables.

Download and place the script file and the license.txt in the same folder and run:

./install_freesurfer.sh

5. Test it!

Check if your X-server is running then open your Ubuntu terminal and type the freeview command to see if the GUI appears.

Guilherme Bauer Negrini
Guilherme Bauer Negrini
Biomedical Data Scientist | Postdoctoral Associate

Biomedical Informatics and Science