Install CERN’s ROOT on Linux (Ubuntu 12.04, 13.04, 14.04, Fedora)

There comes a time when all particle physicists must grab and install ROOT, and if I may say so what an amazing piece of kit it is. You can do  whole manner of things; plotting simple to more complex graphs using 3D visual libriaies, using the numerous built-in mathematics libraries including RooFit for advanced statistics analyses, utilising the parallel PROOF tools, to the powerful TMVA  for multivariate analyses. Oh did I mention this is all FREE and I have barely scratched the surface with that pitiful list just mentioned. Of course it can ‘do your head in’ but that is just one of those things. Having around experienced users is always helpful and once you get used to it, well it becomes like driving, but instead of pollution you leave behind pretty plots and colourful rainbows.

I have supplied a shell script for Linux Ubuntu 12.04 users which installs the head development version of ROOT if you supply a parameter to the script called head. In my experience with Fedora 15+ ROOT is actually available on the repositories so you can do

sudo yum search root

From there you can choose which you want to install, in the past I have just done

sudo yum install -y root*

But this maybe a little all guns blazing so check out what you think you will need from the search.

Ubuntu script, installs the required libraries and sets up environment for future use, install this by default to /usr/local/root. One thing important for the later versions of Ubuntu is that the explicit linking need be enabled (–enable-explicitlink), already set in the script below. Clearly one must check your architecture this script is designed for 64bit machines.

# Matthew M Reid 30/09/2012. Please use and distribute under GNU licience
# : Script to install CERN root on Ubuntu 12.04
# get number of cores for quick parallel build
echo "Getting required libraries...";
sudo apt-get update
sudo apt-get install x11-common libx11-6 x11-utils libX11-dev libgsl0-dev gsl-bin libxpm-dev libxft-dev g++ gfortran build-essential g++ libjpeg-turbo8-dev libjpeg8-dev libjpeg8-dev libjpeg-dev  libtiff4-dev libxml2-dev libssl-dev libgnutls-dev libgmp3-dev libpng12-dev libldap2-dev libkrb5-dev freeglut3-dev libfftw3-dev python-dev libmysqlclient-dev libgif-dev libiodbc2 libiodbc2-dev subversion libxext-dev libxmu-dev libimlib2 gccxml
# remove any obsolete libraries 
sudo apt-get autoremove
# Build using maximum number of physical cores
numCores=`cat /proc/cpuinfo | grep "cpu cores" | uniq | awk '{print $NF}'`
# Define install path
if [  "x$1" = 'xhead' -o "x$1" = 'xHEAD' ]; then
  echo "Downloading development head version from svn..."
  svn co root
  cd root
sudo mkdir -p $installPATH
./configure linuxx8664gcc --enable-explicitlink --all --enable-minuit2 --enable-roofit --enable-table --enable-shared --enable-xml --enable-reflex --enable-python --enable-gdml --prefix=$installPATH
make -j $numCores
sudo make install
# create .bashrc if not exists or insert line if it does
sourceroot=". $installPATH/bin/"
if [ -f ${HOME}/.bashrc ]
    if grep -q $sourceroot ${HOME}/.bashrc  
         $sourceroot >> ${HOME}/.bashrc
  echo $sourceroot >> ${HOME}/.bashrc
  #sed -i '1i #!/bin/bash' ${HOME}/.bash_profile
. ${HOME}/.bash_profile
# with environment set do ldconfig
sudo ldconfig
echo "...done."

You can save this to a file to the downloaded root source directory and then change permissions and execute

chmod +x
# for latest release download it and unzip it yourself, execute the script in the same folder
# for development installation. This is not the recommended method as can change often.
./ head

I would like to remind people about the linking procedure in Ubuntu, in particular when compiling ROOT code from the command line. Always link the libraries at the end of your command, i.e.

g++ -W -Wall `root-config --cflags' test.cpp -o test.o `root-config --glibs`

Where the main point to take note of here is that the `root-config –glibs` which contains the path and set of core libraries to link against are at the end of the sequence. This drove me nuts for about an hour the other day 🙂 as in Fedora and most other Linux distributions it doesn’t matter.

14 comments on “Install CERN’s ROOT on Linux (Ubuntu 12.04, 13.04, 14.04, Fedora)

  1. Reblogged this on Techno Krat and commented:
    Not related to Physics in any way……(with exception of action vs reaction). ROOT is quite diversified framework.It is next level for data analysis and data processing.
    By using ROOT we can also contribute some tineee-wineee work in great Project.

  2. […] ← Install CERN’s ROOT on Linux (Ubuntu 12.04) […]

  3. Tialis says:

    Excellent macro! Could you please help me with this? In the install process it prompts:

    In file included from input_line_6:1:
    In file included from include/Rtypes.h:30:
    In file included from include/Rtypeinfo.h:32:
    In file included from /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/typeinfo:35:
    /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/exception:38:10: fatal error: ‘bits/c++config.h’ file not found
    Error: Error loading the default header files.make: *** [core/base/src/G__Base1.cxx] Error 1
    grep: /usr/local/root/bin/ No existe el archivo o el directorio
    ./ línea 35: /usr/local/root/bin/ No existe el archivo o el directorio
    ./ línea 42: /home/tialis/.bash_profile: No existe el archivo o el directorio


    I don’t know if other people get the same think… I will try downloading root version myself and installing without the “head” to see if it works.

    Thank you!

    • mattreid9956 says:

      I am not sure downloading the current pro-5.34 release will help you. Which distro of Linux are you using? This seems to be an issue locating the named header file “bits/c++config.h”. I would suggest you do

      locate c++config.h

      This will tell you where the file is located and there is probably some mismatch in paths going on. You could then add it manually to the Makefile with a -I/usr/include/. If you have an old version of Ubuntu I would do an update as a quick search on google for “g++ ‘bits/c++config.h’ not found'” suggests that this was fixed in gcc4.6, even though you seem to have 4.7… Try

      sudo apt-get update
      sudo apt-get install -y autotools-dev autoconf-dev automake-dev g++ build-essential
      sudo apt-get autoremove

      There are lots of potential solutions although some in my opinion seen a little dangerous such as changing /usr/include paths…

      I would be surprised if you can even compile a simple example below, main.cpp:-

      int main( int argc, char** argv )
      throw 20;
      catch (int e)
      std::cout << "An exception occurred. Exception Nr. " << e << std::endl;
      return 0;

      g++ -m64 main.cpp

      Try that, if you still need help please just ask!

      • Tialis says:

        I resolved it just by downloading from the svn 5-24-04 and using the script without the “head”.

        The thing is I am finding huge trouble installing MARS (software based on ROOT) because when the Makefile begins the linking, it just prompts “undefined reference” as crazy. The interesting point is that in Ubuntu 10.04 works just fine, but in Ubuntu 12.04 this happens. Is there a difference between the “linking” sintax for this two versions of Ubuntu?

        Thank you for your help!

      • mattreid9956 says:

        Interesting that it worked?! Good for you I will try look into why the head version has issues but as a note maybe I advise others to follow suit, the head version can change frequently. I have not come across MARS if you send me a link to the source I can take a look at compiling it? In 12.04 some of the linking proceedure changed, you need to put things at the end of the command line and in a Makefile do something along the lines of:-

        main : main.cpp $(OBJECTS)
        @echo “Linking “$@
        @$(CXX) $(CXXFLAGS) -o $@ $< $(OBJECTS) $(LIBS)
        @echo "Done."

        Let me know how it goes, or send me a link.

  4. Tialis says:

    Arrrgh… after 2 days of Makefile hell, I just found the solution. In the Makefile linking process, the order of the libraries was not correct. The last one needs to be the one created in the Makefile, and just before, the libraries from ROOT…

    Thank you for the tutorial! it was really helpfull!

  5. […] 10.04 & 12.04, so I hope this macro can help you guys out. It was originally programmed by Matthew M. Reid and here we show what we think would be certain useful modifications and […]

  6. Ome says:

    Are there any guide where a step by step installation procedure is given?

    • mattreid9956 says:

      Step-by-step is already in the script. You can download the script and copy paste each line by line if you want to? The idea here is that you should in theory just be able to run the script for Ubuntu and it will install the programme. I would maybe refer you to as they go through this line-by-line in more detail. Hope that helps!

  7. bayat says:

    hi Dear mattreid9956,
    i save the your exact script in to a file named “” and then change permissions and execute
    with commands:
    chmod +x
    but running root i encountered with this result:
    No command ‘root’ found, did you mean:
    command ‘roottv’ from package ‘xawtv’ (universe)
    command ‘rott’ from package ‘rott’ (multiverse)
    command ‘rbot’ from package ‘rbot’ (universe)
    root : command not found.

    is it necessary to change your script in my root installation on ubuntu 12.04 (64-bit)?
    what dose this mean:
    g++ -W -Wall `root-config –cflags’ test.cpp -o test.o `root-config –glibs`

    • mattreid9956 says:

      ROOT is the package that you are attempting to install, if you have successfully install it using the script or otherwise then typing root in the terminal will open up a ROOT Cint console. Did you download the latest version of ROOT like I suggested from their website? The latest version is here You then need to unpack it, and copy the script into the root directory. I hope that is a little clearer. In the g++ line you mention, the `root-config –cflags` specifies the include paths and the `root-config –glibs` specifies the installed library locations with some default ones to link against to run ROOT.

  8. Venkat Kaushik says:

    I tried installing root (v5.99.01 – head) on Ubuntu 14.04 and got the following error:
    *** Building libAfterImage …
    Generating dictionary graf2d/asimage/src/G__ASImage.cxx…
    core/utils/src/rootcling_tmp -f graf2d/asimage/src/G__ASImage.cxx -c /home/venkat/opt/root/build/root/graf2d/asimage/inc/TASImage.h /home/venkat/opt/root/build/root/graf2d/asimage/inc/TASImagePlugin.h /home/venkat/opt/root/build/root/graf2d/asimage/inc/TASPluginGS.h /home/venkat/opt/root/build/root/graf2d/asimage/inc/LinkDef.h
    make[1]: Entering directory `/home/venkat/opt/root/build/root/graf2d/asimage/src/libAfterImage’
    gcc -m64 -O3 -DNO_DEBUG_OUTPUT -fPIC -I/usr/include/freetype2 -c asfont.c -o asfont.o
    asfont.c:67:33: fatal error: freetype/freetype.h: No such file or directory
    # include
    compilation terminated.
    make[1]: *** [asfont.o] Error 1
    make[1]: Leaving directory `/home/venkat/opt/root/build/root/graf2d/asimage/src/libAfterImage’
    make: *** [graf2d/asimage/src/libAfterImage/libAfterImage.a] Error 2
    make: *** Waiting for unfinished jobs….

    I noticed that freetype.h was in /usr/include/freetype2/freetype.h

    so I applied this fix by adding the following lines to the install script (just after the svn checkout (after line 22)

    ## complains about #include
    test ! -d $freetypeIncDir && \
    echo -n “creating $freetypeIncDir …” && \
    sudo mkdir -p $freetypeIncDir && \
    cd $freetypeIncDir && sudo ln -s ../freetype.h && cd – > /dev/null && echo ” done”

    • mattreid9956 says:

      Just to note, the recommended version of ROOT to use according to the website is Pro, version 5.34/21 recommended (see also the release notes). Anything else may not be stable.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s