Installing CERN ROOT from Precompiled Binaries on macOS and Linux

Petr Stepanov
5 min readJan 29, 2019

CERN ROOT is a powerful framework, a C++ library for processing and manipulating data.

The library setup and use might seem a little overwhelming for a beginner level computer user because:

  • In order to set up the library user has to be familiar with basic command-line tools.
  • To compile a standalone executable from a number of sources one has to know the syntax of the makefiles.
  • There is some specificity towards building standalone ROOT applications with Roofit or GUI.
  • Setting up an IDE can be tricky.

I’ve been using the ROOT libraries during my graduate school and I’m willing to share some experience here. Hopefully it will help out and save some time for other people in this field. Generally speaking there are two ways to install ROOT:

Generally speaking there are two ways to install ROOT:

  1. Install from a precompiled binary that matches your operational system and compiler version. This option works great for users that just need to run ROOT application.
  2. Compile ROOT binaries from source. Use this option if you are developing ROOT-based C++ application that require code debugging. Additionally, compiling ROOT from source may be your only option if ROOT binaries for your operation system are not presented on the official website.

In this article we will only cover the installation of ROOT from precompiled binary files. If you need to compile ROOT from source, check out my correspondent notes on Medium or follow official instructions here.

Installing ROOT on macOS

No matter what OS you are using your ROOT install should start with installing build prerequisites that are listed here. For macOS those are Xcode Developer Package and XQuartz.

  1. xCode can be obtained through App Store. After installing xCode go and install Command Line Tools for xCode. The install dialog will pop up when you first start xCode. Alternatively you can accept xCode license and install Command Line Tools in Terminal: sudo xcodebuild -license && xcode-select --install.
  2. Download and install xQuartz from official website.

You have to make sure you’re downloading the correct ROOT binary file. Firstly, the binary has to match your operation system version. Check your macOS system version under Apple’s menu → About This Mac.

Fig. 1. Compiler versions are stated on the ROOT download page in the left column (e.g. gcc 4.8 or clang100)

Secondly, check that your compiler (clang) version matches the one specified on the binary. To determine your system’s clang version type in terminal clang —-version:

Fig. 2. Notice the system’s Clang version matches the one on the ROOT binary (previous picture)

What should I do if my clang version does not match the one in the bianry? Depending on the clang version of the binary on the CERN website you would have to install a correspondent xCode version on your computer. (please refer to this website). In case App Store does not offer the xCode version you need you can always grab an older xCode version on Apple Developer website.

Now once you made sure you have the correct xCode version and xCode Command Line Tools installed — go ahead and install the ROOT binary package on your system. Next you’ll have to update your system environment variables. Source ROOT’s script thisroot.sh that takes care of the environment variables in your Bash profile. In Terminal execute:

echo 'source /path-to-your-root-folder/bin/thisroot.sh' >> ~/.bash_profile

In order for the changes to take effect you need to source the modified Bash Profile. In Terminal type source ~/.bash_profile or alternatively logout and login back.

Now you will able to run ROOT by typing root in Terminal.

How different is ROOT setup on Linux?

For a linux machine the process is pretty much the same, even easier. On linux CERN ROOT is built with the gcc compiler.

Like any other ROOT installation we start off with the prerequisites for your specific linux version. Find the list of packages you need here.

Before installing ROOT from precompiled binary package install the development tools. For Ubuntu that would be sudo apt-get install build-essential . Fedora equivalent is sudo dnf install @development-tools .

Next, check your Linux and compiler version in terminal:

lsb_release -a && gcc --version

Depending on the output of the above command copy the link to the ROOT binary that corresponds to your OS and gcc version from official website. (refer to Fig. 1). Download archive with curl and extract. I like having files organized: have downloads in ~/Downloads and store applications in ~/Applications :

mkdir -p ~/Downloads && mkdir -p ~/Applications
cd ~/Downloads
curl -O https://root.cern/download/your-root-version.tar.gz
tar xvzf ./your-root-version.tar.gz -C ~/Applications

It’s a matter of taste. Use your desired locations.

Next set up your environment variables. Typically user-specific environment variables on Linux systems with bash shell should be defined in ~/.profile file. Go ahead and source thisroot.sh in your ~/.profile file:

echo 'source $HOME/Applications/root/bin/thisroot.sh' >> ~/.profile

Unfortunately there is an issue with Ubuntu and its child operation systems (Mint, Elementary OS, Zorin etc). According to the official documentation LD_LIBRARY_PATH variable cannot be set in ~/.profile. Variable value turns out to be always empty. This behaviour is reported and it is quite embarrassing that it is still not functioning as intended.

You have to apply a workaround posted here. Simply execute following command to fix the issue:

sudo sed -i 's/use-ssh-agent/no-use-ssh-agent/g' /etc/X11/Xsession.options

Linux distributions that are not based on Ubuntu do not require this workaround. Finally, apply the environment variable changes that we defined:

source ~/.profile

Now you should be able to run ROOT in Terminal by typing root.

Summary

In this article we’ve learned how to set up CERN ROOT library on a Mac machine by either installing the binary distribution.

In the next articles we will go through the process of compiling a standalone executable (with and without GUI), using makefiles and setting up IDE.

Please don’t hesitate to ask questions and post comments.

--

--

Petr Stepanov

Gamma-spectroscopy. Positron annihilation spectroscopy. M.S. in solid-state physics. PhD in photochemical sciences. Desktop, frontend and iOS developer.