How to turn caps lock into another control in Ubuntu

Introduction

It's a personal requirement that every computer that is primarily used only by me has to have the caps lock key reconfigured to act as another control key. This started long ago with the venerable Sun Type 5 keyboard which had the wonderful property of having control and caps lock flipped in hardware for its more common UNIX variant.

Once I had the sweet sweet taste of easy access to the control key, there was no going back.

I used a Sun Type 6 for years on PCs, and although I still have one, it's fallen out of favor because it's too mushy to type on. Instead I use mechanical keyboard instead - but while the ones that I like don't ship with the keys flipped, this is doable in a number of ways in software which is, honestly, fine - if only a little annoying whenever you get a new machine or reinstall the operating system.

Over the years I had done it a few ways - generally the stuff on this page was what I needed. Lately though, I had just been using the option exposed by Gnome and Cinnamon in their configuration dialogs. It has the downside of only working in X (so, not at console), but honestly although I use terminals all day long, I do so within a terminal emulator within an X session. That was fine.

The Problem

It was fine, until it wasn't.

For reasons I don't want to get into, I have to run a virtual copy of Windows on my work machine. This is bad enough, but I also have to run it within VMware Player / Workstation. That's two strikes... but the one that really got me was that remapping caps lock as a control within Cinnamon wasn't playing well with VMware to the point where modifier keys like meta and shift would stop working outside of my VM once I passed my mouse over it, and I do most of my work outside of the VM... so it really hurt. That could not stand. This has apparently been an issue for over 10 years!

I never had this problem with using KVM to run virtual machines so I'm blaming it ultimately on VMware. One more reason not to like that company.

The Solution

I'm running Ubuntu 19.10 on my work machine presently (again, another long story - but Ubuntu is tolerable). The solution is to modify /etc/default/keyboard and put ctrl:nocaps inside of the XKBOPTIONS line. Then run dpkg-reconfigure -phigh console-setup as root, and reboot (logging out and back in or restarting the X server may have been enough - but whatever).

I was then able to unconfigure the Cinnamon menu setting for this, and everything just works once again.

This has the benefit of also working at console, and it should last through kernel upgrades and such.