This section explains the prerequisites and the install procedure for MEGAlib using its setup script. To download the setup script from the command line do:

curl -O


MEGAlib requires a few additional programs. You will usually require a certain version of ROOT and Geant4 to go with a given version of MEGAlib - usually not the very latest one. If you use the MEGAlib setup script, it will automatically download the appropriate version.

In general, you require the following software components:

  1. A fully functional and up-to-date Linux or Mac operating system. The reference system (i.e. the system used to code MEGAlib) is Ubuntu Trusty (14.04).
  2. In addition, make sure you have all development tools installed such as a C and C++ compiler, make, cmake, git, curl, awk, etc.
  3. MEGAlib requires ROOT. If you use the default setup script it will compile its own minimal version. Make sure to take a look at the requirements page of ROOT to make sure you have installed all the necessary software required to compile ROOT: ROOT build prerequisites
  4. MEGAlib also requires Geant4. Again, the MEGAlib setup script will compile its own version. Alternatively you can install it by yourself.
  5. There are a set of optional pieces of code which enhance MEGAlib, such as heasoft (for fits files), doxygen (generate source code documentation), expect (pipeline scripts for parallel processing on clusters), or convert, which are nice to have but not mandatory.

The setup script

The bash script, available from MEGAlib's github repository, is capable of installing MEGAlib along with ROOT and Geant4 on Linux and Mac. The script is intended to be installed by the user in their home directory, for a system-wide, multi-user installation please follow the instructions in the installation manual. Assuming you have followed the instructions in the above section (especially did you make sure to install all the libraries ROOT needs to compile, are git and cmake present?), then installing MEGAlib should be a one-step process. In the directory, where you want to install MEGAlib, do:


This will give you the latest release. Since there is always a long interval between official releases, you can get the head of the development tree via:

bash --release=dev

The script will do the following:

  1. Check if we already have a MEGAlib installation (by default it will search in the directory MEGAlib, or check if it is called from within a MEGAlib installation. If this is the case it will load the command line parameters from the previous run of setup. These are overwritten by the new options you give at the command line.
  2. MEGAlib download: It will check if MEGAlib is present. If not it will download it from the repository (MEGAlib's git repository is the default), if it is present it will update it (but it will make a backup of your src-directory, just in case). If you decided to switch from a release to a development version, it will do that.
  3. ROOT installation: If you have given a path to an existing ROOT installation (--root option), or if it has found an old installation done via this script, it will check if this version is still up to date. If it is not up to date and you have given this ROOT version via the --root option, it will stop here. Otherwise it will download and install the latest version of ROOT compatible with this MEGAlib version.
  4. Geant4 installation: This is exactly the same process as for ROOT.
  5. MEGAlib: It will configure and compile MEGAlib.
  6. Finally it will create a little script which you have to source in order to setup the environment for MEGAlib.

In case something goes wrong, you do get an error message, and you can fix it, then simply restart the setup process. In most cases there is no reason to delete already downloaded files.

Assuming you didn’t get any error, it will tell you something like the following (obviously the path will point to your installation):

In order to run any MEGAlib programs, you have to source the following file first:
source /home/andreas/Soft/MEGAlib/bin/
You can do this in your .bashrc file, or everytime you want to use MEGAlib.

This tiny little script sets the environment variables for ROOT, Geant4, and MEGAlib. Ideally you should put it into your .bashrc file.

If you do bash --help, then you will see a lot of options for the setup script. You can set the name and path of your MEGAlib installation (--megalib-path), you can set the directory where you want to install ROOT and Geant4 (--external-path), you can give the path to an existing ROOT (--root) or Geant4 (--geant4) installation, which you want to use instead of downloading it, you can decide if you want to have the latest release or development version (--release), and you can decide which repository you want to use (--repository, but please stick with git).

The setup script also doubles as update script. Just call it from within your MEGAlib installation and it will update MEGAlib, and if it installed ROOT and Geant4 previously it will also update them.

Installation by hand

If the setup script fails, then you can find a detailed installation description in the file installation manual which can also be found in the MEGAlib/doc directory.

Please take also a look at the change log for the important changes between the versions: ChangeLog