FreeSurfer Build Guide
This page walks through the process of building the freesurfer source code. For an introduction to the repository and the development process, visit the Dev Guide.
Freesurfer depends on a variety of third-party packages, and the following recommends the easiest way to install these requirements on your machine.
This section can be ignored by those developing on the Martinos filesystem.
On ubuntu/debian, install a few of the build dependencies with apt-get:
sudo apt-get update sudo apt-get install build-essential tcsh cmake gfortran \ libglu1-mesa-dev libfreetype6-dev uuid-dev \ libxmu-dev libxmu-headers libjpeg62-dev \ libxi-dev libx11-dev libxml2-utils libxt-dev \ libxaw7-dev liblapack-dev
The remaining dependencies can be built locally using the build_packages.sh freesurfer script, or they can just be downloaded as prebuilt packages (recommended). The following will create a packages directory containing a set of required freesurfer dependencies (built on centos7):
curl https://surfer.nmr.mgh.harvard.edu/pub/data/fspackages/prebuilt/centos7-packages.tar.gz -o centos7-packages.tar.gz tar -xzvf centos7-packages.tar.gz
Freesurfer is supported on OSX El Capitan (10.11) and later, and we recommend using the brew package manager to install a few of the build dependencies:
brew install cmake gcc5 qt5
The remaining dependencies can be built locally using the build_packages.sh freesurfer script, or they can just be downloaded as prebuilt packages (recommended). The following will create a packages directory containing a set of required freesurfer dependencies (built on OS X 10.11.6):
curl https://surfer.nmr.mgh.harvard.edu/pub/data/fspackages/prebuilt/osx10.11-packages.tar.gz -o osx10.11-packages.tar.gz tar -xzvf osx10.11-packages.tar.gz
get source from github or fork --
get annex data --
Freesurfer supports both in-source and out-of-source builds using CMake (although tests can only be run from an in-source build). To configure a simple in-source build tree, enter the top-level directory of the repository and run:
External users not developing on the Martinos filesystem will get an error saying "External FreeSurfer developers must provide a valid FS_PACKAGES_DIR path". To resolve this, you must point cmake to the full path of the packages directory configured above with the following option:
cmake . -DFS_PACKAGES_DIR="/path/to/packages"
This path can also be set in an FS_PACKAGES_DIR environment variable, so that it doesn't need to be supplied on the command line for every new configuration.
By default, freesurfer will install to /usr/local/freesurfer, but the install path can be configured with:
cmake . -DCMAKE_INSTALL_PREFIX="/path/to/desired/install"
Alternatively, this path can be set in an FS_INSTALL_DIR environment variable to avoid having to specify it for every configuration.
Optimization and Debugging
Once your build tree has been configured appropriately, freesurfer can be compiled with make and installed with make install. Additionally, unit and regression tests can be run with make test (previously make check) from individual subdirectories or from the top-level. The current 8-threaded build time is roughly 6 minutes. Single-threaded builds can take between 10 and 20 minutes.