25th Jan 2023

The following command will map the Caps Lock key to Escape:

setxkbmap -option caps:escape

However, the mapping only lasts for the duration of the current desktop session. I’ve also found it to be unreliable: sometimes the mapping succeeds but Caps Lock continues to toggle caps lock while also sending Escape.

This following will permanently map Caps Lock to Escape, in a way that I’ve found it to be a lot more reliable:

dconf write /org/gnome/desktop/input-sources/xkb-options "['caps:escape']"

The above works on not only Ubuntu, but distros that use Gnome for a desktop environment.

You may need to install dconf-cli if you don’t already have it:

sudo apt install dconf-cli

Further reading