Hacking:Building/Linux

This guide will explain you how to install GIMP, even without root/admin permissions/privileges. It will explain how to install GIMP to a custom location so that it won’t conflict with your existing GIMP installation. Through this guide, I’m going to use the bash shell for executing stuff from the command line – it’s usually located in /bin/bash.

Perquisites:

You should know roughly what is a command-line/terminal/shell. You should also know how to open the command-line/terminal/shell.

The Basics - Environment Variables

The main "problem" (don't worry, it's solvable) with compiling gimp on Linux, is environment variables. There are 3 environment variables which we should get to know when compiling things on Linux, and we’ll now present them:

PATH

First of all, this environment variable specifies where to look for executables. When you type "gimp" in the command line, all the directories inside the path will be searched.

As you can see, the path is composed out of a list of paths to directories, separated by ':' signs. The order of directories inside the path does matter! Directories which are listed first, are searched first!

PKG_CONFIG_PATH

This environment variable tells the pkg-config tool (a tool which is used to resolve most dependencies in GIMP’s compilation) where to look for the config files (which are used by pkg-config) for installed libraries.

LD_LIBRARY_PATH

Many executables used files which are called shared libraries – these files contain functionality that should be shared between executables. One example which you should know (if you are a Linux user) is Gtk+ – the library which is used by many applications (including GIMP) to create the user interface.

The executables search for these libraries inside some directories which are considered as “default”. So, in order for us to install and use libraries in other locations we need to update this variable to point to the directory leading to these libraries.

CFLAGS, CPPFLAGS, LIBS

These variables are used to specify additional arguments to the C compiler (CFLAGS), the C Pre-Processor (CPPFLAGS) and the linker (LIBS). Since we install things in paths other than the default, we will possibly need to use them to specify the tools where to look for our installed stuff.

What’s the problem with environment variables?

We don’t want to compile GIMP and install it in the default location, because then it may conflict with our existing installation. But if we install GIMP at a different location, we need to configure the environment variables so that the correct versions of libraries will be found and used, both for compilation and for running GIMP.

Preparing for compilation

First of all, we need to decide where do we want to install the alternative version of GIMP. To make it easy to remember and use, we’ll define an environment variable containing that path:

export INSTALL_PREFIX=/vol/scratch/gimp-beta/build

We will also need a directory to download the sources to; this is the directory I used:

export SRC_DIR=/vol/scratch/gimp-beta/src

You’ll need to make sure both of these directories actually exist, and if not, create them. You can do it by running following commands:

mkdir -p $INSTALL_PREFIX
mkdir -p $SRC_DIR

Now, remember the discussion we had about environment variables? Here are the updates we need to do:

In the first line, we update the PATH variable, so that looking for executables will begin in our installation directory (executables will be installed into the bin subdirectory).
In the second line, we tell pkg-config that it should begin searching for library config files in our installation directory. This will resolve many compilation issues! For example, this will allow us to compile plug-ins against our updated version of the GIMP libraries, even if we have the old ones installed.
In the third line, we tell the library loader that it should first of all try to look for libraries in our installation directory – this will prevent it from loading the libraries of other GIMP versions (that can cause trouble...).

Dependencies

Since you already read about GIMP's dependancies in Hacking:Building, you should already know roughly what does GIMP rely on. Any recent linux distribution should have most dependancies listed in the previous page, except for babl and GEGL. If you'll encounter errors in the process, about missing dependencies or too old versions of dependencies, see the troubleshooting section at the bottom of this page.

Compiling babl, GEGL and GIMP from source

The procedure for compiling babl, GEGL and GIMP is very easy once you have the dependencies. Note that the order here matters – we first need to have babl, then GEGL and finally GIMP.

If you downloaded the source tarballs (the filename will end with .tar.gz or .tar.bz2), you'll need to extract them by executing

tar -xf FILE -C DIR

Where FILE should be the path to the file you want to extract and DIR is the directory into which you wish to extract the sources.

Actual Building

For each one of babl, GEGL and GIMP (in this order!) do:

Enter the source directory

cd PATH/TO/DIRECTORY

Replace with apropriate path

If you downloaded a source Tarball, run the configure script with our desired install prefix

./configure --prefix=$INSTALL_PREFIX

Ohterwise, if you downloaded the source from git, run the autogen script with same argument

./autogen.sh --prefix=$INSTALL_PREFIX

If you encounter errors about missing dependancies, look at these suggestions:

When running it for GIMP, if you don't have Python and PyGtk, you'll need to disable them explicitly by appending the following argument to the command above

--disable-python

When running it for GIMP, if you don't have gtk-doc, you'll need to disable it explicitly by appending the following argument to the command above

--disable-gtk-doc

When running it for GIMP, if you got some error message about some missing libraries, and they weren't listed as the core dependancies of GIMP in Hacking:Building, you can try to disable them. You can list the options that the configure script accepts by running

./configure --help

You can do the same with the autogen script (since it passes it's flags to the configure script!)Now, look for some option which is called --disable-XXX or --without-XXX, where XXX is the thing which causes your problem. If you found such an option, simply append it to the list of arguments (without the --help) and try again.

Run make

make

Run make install

make install

Running our compiled version of GIMP

Now, we should be careful before running GIMP. Our compilation was done with some very specific environment variables, and running GIMP will depend on them! So, let’s save our environment variables into a script that runs GIMP:

echo "#! /bin/bash
# set the path to the installation directory
export INSTALL_PREFIX=$INSTALL_PREFIX
# set the path to the directory into which we download the sources
export SRC_DIR=$SRC_DIR
# Now, set mandatory enviroment variables
export PATH=\$INSTALL_PREFIX/bin:\$PATH
export LD_LIBRARY_PATH=\$INSTALL_PREFIX/lib:\$LD_LIBRARY_PATH
# Not needed for running GIMP directly, but needed if you want to compile anything against our
# builds (think of plug-ins, etc.)
export PKG_CONFIG_PATH=\$INSTALL_PREFIX/lib/pkgconfig:\$PKG_CONFIG_PATH
# Now you can run executables our other stuff depending on our environment
# Here we run GIMP, and pass it any arguments given to this script
\$INSTALL_PREFIX/bin/gimp-2.7 \$@
# If you want to run something else, copy paste into bash everything before the line that
# runs GIMP, and then run it
" > $INSTALL_PREFIX/run-gimp.sh
chmod +x $INSTALL_PREFIX/run-gimp.sh

This command creates a script file called run-gimp.sh (inside our installation directory), which sets our environment variables, and then runs GIMP. The script will also contain instructions about running things other than GIMP using our environment. If you finished this step without errors, you should now have a working build of GIMP!
Note: If you compiled a gimp version other than 2.7, replace the 2.7 with the correct version.

Troubleshooting

I’m getting an error about a too low of GTK+/GLib while compiling XXX

You can either update your version of GTK+/GLib using your system’s package manager, or compile GTK+/GLib from source! Compiling these is done exactly like we compiled babl – download the source (either the latest from Git, or a package from the official site), compile and install. You may also need to do something like this to a library called ATK.

I’m getting some error about relative path in the prefix

The installation directory of libraries/executables must be specified in an absolute path and not in a relative path. If you got this error, it means that one of the paths in your environment variables is relative and not absolute – fix that!

I'm getting errors about missing/old version of Gtk+/Glib/etc.

The 3/4 step process described in Hacking:Building for building should work for building most if not all of GIMP's dependancies. Like we compiled GIMP, you should download the sources, run configure then make and finally make install. Use Google or some other search engine to find the website of the package and download it's source from it. Of course that if possible, you should try to install these dependencies through your system's package manager (if you have root permissions) and by that you'll save the time and effort of the compilation.

Notes
The production of the documentation requires docbook and ancillary programs. Here are some of the other programs;gettextautomakedocbook2odfpngcrushpngnqdocbook-xsl docbook-utilsdblatex
Which may or may not already installed. Running autogen will stop at the failed dependency, so install and repeat the process till autogen finishes.