This page is targeted at those who wish to build and develop the FreeSurfer source code on their Linux platform. These instructions have been tested for Centos 6 Desktop Edition, Ubuntu 14.04 LTS, Ubuntu 16.04 LTS, and Debian 8. See the Mac OSX build page for instructions on how to build on Mac OS X platform.

Those who wish to add a binary to the FreeSurfer software suite should consult the 'Adding a new binary to the tree' section of the Developers Guide.

1. Get the Source Code

Users can download FreeSurfer source code via the read-only git repo:

## Get source code files (206 MB)
$> git clone https://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/repo/freesurfer.git

1.1. Get the Data Files

The FreeSurfer repository contains a large number data files which are not included with a default git clone of the repo. Instead, these data files are distributed via the git-annex software. Users who only want the repository for the purposes of compiling binaries and/or inspecting source code, the git clone command from above is all you need to do. Users who want to run build time checks, or perform a full local installation, or just want all the contents of the repository, will need to install git-annex and run the following command:

## Get only the data files required for build time checks (1.9 GB)
$> git annex get --metadata fstags=makecheck .

## Get only the data files required for local installation (4.3 GB)
$> git annex get --metadata fstags=makeinstall .

## Just give me everything! Not Recommended (6.8 GB)
$> git annex get .

2. Install System Libraries

Building freesurfer requires various system specific libraries be installed on your machine. Depending on your specific linux distribution, the required system packages are listed below:

CentOS 6:

$> yum groupinstall "Development Tools"
$> yum install mesa-libGLU-devel \
            freetype-devel.x86_64 \
            libuuid-devel.x86_64 \
            uuid-c++-devel.x86_64 \
            libXmu-devel.x86_64 \
            libXi-devel.x86_64 \
            lapack-devel.x86_64 \
            liblapack-devel.x86_64 \
            libXaw-devel.x86_64 \
            libpng-devel.x86_64

Ubuntu 14.04 LTS / Debian 8:

$> sudo apt-get update
$> sudo apt-get install build-essential \
            tcsh \
            libtool-bin \
            libtool \
            automake \
            gfortran \
            libglu1-mesa-dev \
            libfreetype6-dev \
            uuid-dev \
            libxmu-dev \
            libxmu-headers \
            libxi-dev \
            libx11-dev \
            libxt-dev \
            libjpeg62-dev \
            libxaw7-dev \
            liblapack-dev

Ubuntu 16.04 LTS:
Ubuntu 16 requires all the same packages required by Ubuntu 14 (listed above), along with the additional requirement of installing gcc v4.8 (this is due to errors generated by the default version of gcc included with Ubuntu 16).

## Install gcc/g++/gfortran version 4.8
$> sudo apt-get install gcc-4.8 g++-4.8 libgfortran-4.8-dev

## Set gcc/g++ 4.8 to be the default compiler
$> sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
$> sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50

3. Library Dependencies

In order to compile freesurfer, you will need to download and install our prebuilt bundle of 3rd party dependancies. Download the package and extract its content. Remember the extraction location as you will need to pass that directory to the configure script.

$> cd ~
$> wget ftp://surfer.nmr.mgh.harvard.edu/pub/dist/fs_supportlibs/prebuilt/centos6_x86_64/centos6-x86_64-packages.tar.gz
$> tar -xzvf centos6-x86_64-packages.tar.gz
$> ./centos6-x86_64-packages/setup.sh

4. Setup, Configure, Make

Determine the location you want Freesurfer to be installed. For example, in the case below we will assume the user wants freesurfer to be installed in /home/USER/freesurfer. Type the following commands in the top-level Freesurfer directory (the directory that contains configure.in and all the mri_* and mris_* directories.):

$> cd ~/freesurfer
$> ./setup_configure

## Centos/Debian
$> ./configure --disable-Werror --with-pkgs-dir=/home/username/centos6-x86_64-packages --prefix=/home/username/fs_install

## Ubuntu
$> ./configure --disable-Werror --with-pkgs-dir=/home/username/centos6-x86_64-packages --prefix=/home/username/fs_install --disable-xawplus-apps --disable-tcltk-apps

$> make -j4

## Run build time checks. Requires data files. (See "Data Files" from above)
$> make check

## Install locally. Requires data files. (See "Data Files" from above)
$> make install

Done!

Send your comments/questions/feedback to zkaufman@nmr.mgh.harvard.edu