I would look into ~/.xinitrc,
but there is a myriad of other possibilities depending on your window
manager or desktop environment (see, for example, How do I set Xmodmap on login?). There is not enough information in the question to find it out.
But remapping CapsLock to Escape is one of the canonical mappings provided
by the the XKB extension, as listed in man xkeyboard-config.
Just issue
setxkbmap -option 'caps:escape'
and voilà, CapsLock is an Escape. It can be made persistent
by editing the "XKBOPTIONS" line of /etc/default/keyboard:
XKBOPTIONS="caps:escape"
Debian and Ubuntu set the keyboard based on that very file, so it is a reliable solution. You can delete .Xmodmap then and just make sure no other program meddles with the keymap.