You don't mention which version of Ubuntu you are using but packages are only available for 14.04 through 15.10 at this time as it's been almost 2 years since the PPA has been updated. Since 14.04 is the only one of these currently supported, I'm providing instructions for that version.
For 14.04
Run the following commands in a terminal
sudo add-apt-repository ppa:dpmva1/ppa
sudo apt-get update
sudo apt-get install e2defrag
EDIT from man page:
Note that unlike the fsck program, defrag MUST NOT be run on a mounted file system device
(unless invoked with the -r (readonly) option, which is always safe). Also note that if you
defragment a partition containing a bootable kernel image and are using lilo ( grub doesn't
care unless you have it installed in the partition using blocklists instead of the MBR ), you
will have to reinstall the boot loader for that image (since the location on disk of the image
may have changed).
Remember, if defrag fails to complete for any reason (including power glitches, kernel bugs
etc.), you will be left with a terminally sick, and possibly completely unreadable, filesystem,
so backup any valuable data before you start.
Installation tested on 14.04.5 I have no reason to expect the point release is relevant.