Installing ANTsR

All code for this document is located at here.

In this tutorial, we will go through the steps of installing ANTsR, including those for ITKR.

There are 2 options for installing ITKR and ANTsR: one is using devtools and the other is installing the binaries. We recommend installing the binary file of ITKR and using devtools to install ANTsR.

Option 1: Using Devtools

Install devtools

You must have devtools installed to install from GitHub.

packages = installed.packages()
packages = packages[, "Package"]
if (!"devtools" %in% packages) {

Please refer to installing devtools for additional instructions or troubleshooting.


You need to install Command Line Tools, aka the command line tools for Xcode, if you have not already. is a great tutorial how.


Although still untested there is a good tutorial on running FSL on Windows as well as ANTsR on Windows through Linux Subsystem.

cmake and git

ANTsR depends on ITKR, which states in the DESCRIPTION file:

OS_type: unix
SystemRequirements: cmake, git, clang (recommended)

so you must install git and cmake. Also, you must have a Unix-based system get these programs to work, so Windows users are out of luck. The continuing discussion will only support Linux variants and Mac OSX.

Setting the PATH

In either Linux or Mac OSX, there is a PATH “environment variable”. This tells your computer which folders to look in when you type in a command. For example, the cd command changes directories and the code (or compiled code) to do that is located in a folder. When you type cd, your computer looks (in order) in the folders specified in the PATH variable.

In a shell (discussed later), you can type

which cd

and find the executable that you are calling when you actually execute the cd command.

Testing if cmake and git are installed

Below are some instructions testing whether git and cmake are installed. If they are not installed, then there are instructions to install them.


If you are on Mac OSX open up the Terminal and type

which cmake
which git

and if no paths are returned, then you don’t have these installed.

Installing Git

Please go to if you do not have git installed. It is a good and comprehensive tutorial on how to install git (but you may already have it installed).

Installing CMake

You can download CMake and you can download either the Binary (recommended) or the Source (more advanced, not covered here - see install instructions from CMake website).

After downloading the Binary, you will have the CMake application. If you use the dmg, you can drag and drop the application into the /Applications folder. If you use bash (I believe is the default), then open the Terminal, type vi ~/.bash_profile. This will open an editor (vi) and type the letter i, go to the bottom of the document, and copy and paste

export PATH=$PATH:/Applications/

to the bottom. To exit type ESC+:+wq. The ESC escapes anything you were doing (like inserting text), the colon is telling vi you’re in "Colon mode, the w means write the file, and q means quit. If you edited a file and don’t want to save changes, use :q! (quitting and not saving/writing).


You open up the Terminal and type :

which cmake
which git

and if no paths are returned, then you don’t have these installed.

Installing git

Depending on the variant of Linux you are on, the following commands should work:

sudo apt-get install git # ubuntu/debian
sudo yum install git # centos/fedora

Installing cmake is a good discussion on how to install cmake on Ubuntu. is a good discussion on how to install cmake on Centos (hint sudo yum install cmake).

Installing ITKR

You must install ITKR and ANTsR from R from a Terminal NOT from a GUI (RStudio/R application).

After devtools is installed, you can update ITKR:


This will take a lot of time to compile and such.

Installing ANTsR

You must install ITKR and ANTsR from R from a Terminal NOT from a GUI (RStudio/R application).

If ITKR did not install, stop. Stop here. ANTsR cannot work without ITKR. If you think ITKR has a configuration problem and NOT a problem with your setup, you should open an issue and see if the authors would be able to fix it. Make sure you try the same steps on another machine (or virtual machine) before saying that something is “broken”.

Again, we can install ANTsR using `devtools:


This also will take a lot of time to compile.

Updating ANTsR

ANTsR takes a long time to compile and ITKR takes even longer. If you want to re-install or update ANTsR from GitHub, but not update any of the dependencies (including ITKR), then you should run:

neuroc_install("ANTsR", upgrade_dependencies = FALSE)

Option 2: Installing Binaries

If you go to the Release Page for ANTsR they have pre-built binary releases for different systems. If not specified, a .tgz should be the binary for the Mac OSX version and the .tar.gz should be that for a PC/Linux. You should check to see when the last release was made as some of these may be largely outdated, may not have the latest bug fixes, and may not be versioned corresponding to some common rules.

Troubleshooting errors

If you see the following error when installing ITKR:

./configure: line 26: cmake: command not found

guess what? cmake cannot be found. You either need to repeat the steps above or try to install ITKR using a Terminal (by calling R) instead of RStudio or the R application. This is due to some environment variables (not PATH though) not being available to those programs. Also, make sure you put export before PATH, and make sure PATH is not defined somewhere lower in the ~/.bash_profile and overwrites your changes.

You can see all of PATH by typing in the Terminal:

echo ${PATH}


One of the packages ANTsR suggests is rgl. For Mac OSX, this should be installed with the package if not already installed, which usually works OK. On some Linux variants like Ubuntu, the installation may fail.

If you have errors installing rgl, then according to a StackOverflow post, you can install using the following command:

sudo apt-get install r-cran-rgl