When have you last used your caps lock key? On purpose? Right...
In Gnome
Make it an additional ESC key by going to System -> Preference -> Keyboard -> Layouts -> Options -> CapsLock key behavior and select "Make CapsLock an additional ESC".
On recent Ubuntus this option was removed so you have to resort to using dconf Show archive.org snapshot .
dconf write /org/gnome/desktop/input-sources/xkb-options "['caps:escape']"
Or, open Tweak advanced GNOME 3 settings
and follow Keyboard & Mouse
-> Additional Layout Options
to chose the same option as described above.
In any X11 window manager
Simply run setxkbmap -option caps:escape
. If you want it to happen every time, put it into some place where it get's executed automatically, like .xinitrc
or .xsessionrc
.
If you want to swap Escape and Caps Lock, you can use setxkbmap -option caps:swapescape
.