First run the sudo apt-get install build-essential to install the necessary compiler tools.

Then, install the following packages:
libsdl-image1.2
libsdl-image1.2-dev
guile-1.8
guile-1.8-dev
libsdl1.2debian-arts
libartsc0-dev
libaudiofile-dev
libesd0-dev
libdirectfb-dev
libdirectfb-extra
libfreetype6-dev
libxext-dev
x11proto-xext-dev
libfreetype6(upgrade)
libaa1
libaa1-dev
libslang2-dev
libasound2
libasound-dev

You can install them via Synaptic Package Manager (System/Administration/) one by one , or type the following in the terminal:
sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 guile-1.8-dev libsdl1.2debian-arts libartsc0-dev libaudiofile-dev libesd0-dev libdirectfb-dev libdirectfb-extra libfreetype6-dev libxext-dev x11proto-xext-dev libfreetype6(upgrade) libaa1 libaa1-dev libslang2-dev libasound2 libasound-dev

After this download libgraph-1.0.1 (This is the link) to your

Home folder.
Right click on it and press “Extract here”
Now type in the terminal
./configure
sudo make
sudo make install

This completes the installation. :)

Now just add the following lines in your program:
int gd,gm=VGAMAX; gd=DETECT;
initgraph(&gd,&gm,NULL);

and compile using g++ like:
g++ test.cpp -o test.o -lgraph
And execute the program by ./test.o

If on compile it gives you error that says “could not load shared libraries” or something like that just run the following command

that it should fix it.
sudo cp /usr/local/lib/libgraph.* /usr/lib

in case using c files, just include the header file graphics.h and then proceed simply with the program just like in tubo c. Compile the program by:

gcc filename.c -lgraph

if u get string conversion error try this:

gcc filename -lgraph -Wno-write-string

if you get this error(/tmp/ccYXvPbQ.o:(.eh_frame+0×12): undefined reference to `__gxx_personality_v0′

collect2: ld returned 1 exit status

)

then try this

gcc filename -lstdc++ -lgraph -Wno-write-strings

For executing the program, use the command ./a.out

The error “./a.out: error while loading shared libraries : libgraph.so.1:cannot open shared object file: No such file or directory” can be solved by

sudo cp /usr/local/lib/libgraph.* /usr/lib

An example program(to print a rectangle) :
#include<iostream>
#include<graphics.h>

int main()
{
int gd=DETECT, gm=VGAMAX;
initgraph(&gd, &gm, 0);
moveto(0, 0);
rectangle(50,50,500,200);
getchar();
closegraph();
return 0;
}

Run this and if any queries leave a comment.