Installation of MRtrix3 and all its dependencies from source

The following instructions list the steps I used to compile MRtrix3 natively on a local HPC cluster or other systems where you may not have admin access. For build instructions on your local machine, please refer to the documentation pages.

Replicating these instructions line-for-line may not work on another system; I’m just providing these instructions here in case they help to point somebody in the right direction, or encourage users to try a native installation rather than resorting to transferring binaries compiled on another system.

Installing a C++11-compliant g++ from source

Note that during this process, there will be three gcc directories created: one is for the source code (including that of some prerequisites), one is for compilation objects, and one is the target of the final installation (since you almost certainly won’t be able to install this version of gcc over the top of whatever is provided by the HPC sysadmin).

svn co svn:// gcc_src/

(Don’t checkout the trunk gcc code; MRtrix3 will currently not compile with it)

The following gcc dependencies will be built as part of the gcc compilation, provided that they are placed in the correct location within the gcc source directory.

tar -xf gmp-6.1.1.tar.bz2
mv gmp-6.1.1/ gcc_src/gmp/
tar -xf mpc-1.0.3.tar.gz
mv mpc-1.0.3/ gcc_src/mpc/
tar -xf mpfr-3.1.4.tar.gz
mv mpfr-3.1.4/ gcc_src/mpfr/

With the following, the configure script (which resides within the gcc_src directory in this example) must not be executed within that directory; rather, it must be executed from an alternative directory, which will form the target location for the compilation object files. The target installation directory (set using the --prefix option below) must be a location for which you have write access; most likely somewhere in your home directory.

mkdir gcc_obj; cd gcc_obj/
../gcc_src/configure --prefix=/path/to/installed/gcc --disable-multilib
make && make install

Installing Python3 from source

My local HPC cluster provided Python version 2.6.6, which was not adequate to successfully run the configure and build scripts in MRtrix3. Therefore this necessitated a manual Python install – a newer version of Python 2 would also work, but downloading Python 3 should result in less ambiguity about which version is being run.

tar -xf Python-3.5.2.tgz
mv Python-3.5.2/ python3/
cd python3/
cd ../

Installing Eigen3

tar -xf 3.2.8.tar.gz
mv eigen* eigen3/

Installing MRtrix3

Personally I prefer to install a no-GUI version of MRtrix3 on high-performance computing systems, and transfer files to my local system if I need to view anything; so I use the -nogui flag for the configure script.

git clone
cd mrtrix3/
export CXX=/path/to/installed/gcc/bin/g++
export EIGEN_CFLAGS="-isystem /path/to/eigen3/"
export LD_LIBRARY_PATH="/path/to/installed/gcc/lib64:$LD_LIBRARY_PATH"
../python3/python configure -nogui
../python3/python build

If you encounter issues when running MRtrix3 commands that resemble the following:

mrconvert: /usr/lib64/ version `GLIBCXX_3.4.9' not found (required by mrconvert)

This indicates that the shared library of the compiler version installed on the cluster is being found before that of the C++11-compliant compiler installed manually. The lib64/ directory of the manually-installed gcc version must appear before that of the version installed on the cluster in the LD_LIBRARY_PATH environment variable.