This can usually be implemented within the desktop environment (eg KDE and Gnome both have graphical utilities for doing this).
You can also achieve the desired button swapping using xinput (which can be automated on login via autostart script). The basic idea described here...
http://xahlee.info/linux/linux_swap_mouse_buttons.html
or by creating a custom Xorg input config file. For example
http://linus.haxx.se/2013/03/07/mous...-in-xorg-conf/
The physical button numbering can be discovered using xev, and a button mapping assignment made accordingly.