How to install CERN ROOT

There are many good ways and many bad ways to install ROOT on a machine. Here are two of the good methods. In this method, any number of root versions can be build and install in the same machine.

Update (2021-05-05): The first method is preferred now.  However, one might opt the second method for the older versions of root (before v5.36.34).

Note: Sudo power is not needed for installation of ROOT except in the case of installing the prerequisites.

Warning: Newer ROOT versions requires active internet connection to build.

 

Method 1:

Execute the command mentioned bellow. That is all. The commands are self-explanatory.

  1. Install the ROOT Prerequisites compatible with your machine. It looks like the following for Ubuntu.
    sudo apt-get install dpkg-dev cmake g++ gcc binutils libx11-dev libxpm-dev libxft-dev libxext-dev python libssl-dev gfortran libpcre3-dev xlibmesa-glu-dev libglew1.5-dev libftgl-dev libmysqlclient-dev libfftw3-dev libcfitsio-dev graphviz-dev libavahi-compat-libdnssd-dev libldap2-dev python-dev libxml2-dev libkrb5-dev libgsl0-dev libqt4-dev
  2. Execute the commands mentioned bellow in a terminal.
    cd

    mkdir products (if not created earlier)

    cd products

    mkdir ROOT (it not created earlier)

    cd ROOT

    wget https://root.cern/download/root_v6.22.08.source.tar.gz (or whichever you like from Downloading ROOT Site)

    rm -rf root_v6.22.08 (if already present)

    tar -zxvf root_v6.22.08.source.tar.gz

    mv root-6.22.08 root_v6.22.08

    mkdir root_v6.22.08-build

    cd root_v6.22.08-build

    cmake -Dminimal=OFF -Dgdml=ON -Dxrootd=OFF -DCMAKE_INSTALL_PREFIX=/home/maxi/products/ROOT/root_v6.22.08/ /home/maxi/products/ROOT/root_v6.22.08/ (replace 'maxi' with username and add or remove any more required flag (i.e. -Dminuit2=ON, etc.).)

    make -j2 (change '2' to any number less than the available CPU cores)

    make install

    cd ..

    rm -rf root_v6.22.08-build
  3. At this point, the machine doesn’t know the location of the ROOT installation. There are two ways to set the ROOT environent. The first way is to add the following to the .bashrc file.
    # For ROOT
    export ROOTSYS=/home/maxi/products/ROOT/root_v6.22.08/
    export PATH=$ROOTSYS/bin:$PATH
    export LD_LIBRARY_PATH=$ROOTSYS/lib/:$LD_LIBRARY_PATH

    Whenever a new terminal is opened, this file is sourced automatically.
    The second way is to source the ROOT directly (without editing the .bashrc file) by executing the following command in the a terminal which has been already opened.

    source /home/maxi/products/ROOT/root_v6.22.08/bin/thisroot.sh
  4. Open a new terminal. Execute root -l. You should see the root prompt now.
  5. One might build and install any number of ROOT versions in the ROOT directory. Just replace the directory path in the .bashrc file and you are good to go with the preferred version.

Method 2:

  1. Some packages need to be installed prior to install ROOT. These packages can be found on the Build Prerequisites Site. Search for the Operating System on which your PC is running. I recommend to install both the Required Packages and Optional Packages. Just copy the command line into a terminal. It should look like this
  2. Download any stable version (not PRO or DEV) of Source distribution (i.e. root_vX.XX.XX.source.tar.gz) from Downloading ROOT Site.

  3. Make a new directory/folder named products under /home/user/ and then go the directory on a terminal. Execute pwd  command on the terminal. It should look like this. If it is not then you are in wrong directory.
    /home/maxi/products
    where maxi is the user.

  4. Copy the ROOT Source file into this directory. Extract the source file using the following command.
    $ tar -zxvf root_vX.XX.XX.source.tar.gz
    One directory/folder containing the required files will be created. The file name should be root_vX.XX.XX, otherwise rename it. Then go to root_vX.XX.XX directory. Execute pwd command in the terminal. It should look like this.
    /home/maxi/products/root_vX.XX.XX
    If it is not then you are in wrong directory.
  5. Use the following command to configure the ROOT installation.
    $ ./configure
  6. After finishing the process, run the following command.
    $ make -jN
    where N is the number of thread(s)/core(s) on which you want to run the process. If you have a quad-core PC then use 3 (i.e. make -j3).
  7. Then try the next command.
    $ make install
    If everything goes fine then this message should come up on the terminal.
    Everything already installed!
    “source bin/thisroot.[c]sh”
  8. Now open a new terminal. Open the .bashrc file in any editor and add the following lines at the end of the file. Do not forget to modify the user name and version before adding the lines to .bashrc file. Save the file.
    # For ROOT
    export ROOTSYS=/home/user/products/root/root_vX.XX.XX
    export PATH=$ROOTSYS/bin:$PATH
    export LD_LIBRARY_PATH=$ROOTSYS/lib/:$LD_LIBRARY_PATH
  9. Open a new terminal. Execute root. The root prompt should open. It means that you have successfully installed root on your system.
  10. Now, I will not use this root prompt to execute any program. I prefer to make executables with c++ using only the specific classes required.
    So, execute .q on the terminal and it will make you out of the root prompt.