I am using this on my .bashrc file:


setxkbmap -option ctrl:swapcaps

I did this, basically, because I am using Emacs a lot. It seems to work most of the time.

Unfortunately, 2 problems keep happening:

(i) - After the PC starts, it takes a while to work. It is not instantaneous which intrigues me, since this seems to be something "small" to change;

(ii) - Sometimes, out of the blue, it has stopped working, and then, suddenly, the swap is back. This happened one time today.

Although it was just one time, it is really annoying because I have changed the keybinding recently. So, I am already making mistakes sometimes while getting used to it. If I cannot trust this keybinding, the mistakes are going to be even more frequent.

I have a huge knowledge gap on .bashrc file configurations. Maybe, there is some inconsistency in my file. Here is a repository on GitHub showing the whole .bashrc file.


  • 1
    .bashrc is only referenced with the terminal opening into a login shell. Unless you're logging directly into a terminal login shell (Bash) it won't load at start. It also may not be persistent. GUI environments though don't refer to .bashrc when you load up on boot.
    – Thomas Ward
    Jul 22, 2021 at 16:00
  • Thanks, @ThomasWard. This explanation makes a lot of sense. Do you recommend another place for me to insert this setxkbmap definition? I would like to have it as a persistent change and loading up on boot. Jul 22, 2021 at 17:30
  • 1
    I have a couple of potential solutions but i am on the tail end of a very long day and heading to sleep, will share my thoughts tomorrow after sleep.
    – Thomas Ward
    Jul 23, 2021 at 1:43
  • No problem. Have a nice rest :) Jul 23, 2021 at 1:45
  • 1
    TYPICALLY this is done in /etc/rc.local but that's more or less deprecated nowadays in favor of SystemD oneshot units at boot time. Which would work for literally the entire system (or they should anyways). Let me write up an example in an answer. If it works, great, if not, we'll keep chugging along on potential solutions.
    – Thomas Ward
    Jul 23, 2021 at 15:16

1 Answer 1


So, one of the problems you're encountering is the evil that is ".bashrc is only read for Bash shells in the terminal". Your GUI is NOT a Bash shell, so .bashrc is NOT read by the GUI until you open the Terminal and then it activates/applies the keychange.

If we want it to work globally it needs to execute as part of the system independent of the .bashrc. There're two options: Your user crontab for @reboot which is a special case name. OR, a SystemD unit.

(I've tested neither solution, so I can't comment if one will work better than the other, if at all).

Let's start with the cron job option first.

Cron job approach

Open your terminal, and run crontab -e.

Add this line to it:

@reboot setxkbmap -option ctrl:swapcaps

Reboot your system, and see if this works.

If it works, great. If not, then we have to try another approach.

Fallback Solution: Autorun gnome-terminal after login

If all else fails, add gnome-terminal to your startup applications.

First, install gnome-startup-applications:

sudo apt install gnome-startup-applications

Secondly, search your applications for "Startup Applications Preferences"

Add an item for gnome-terminal. That way it'll autorun the terminal automatically.

  • Thanks. It almost works. After start-up, it does not work. But if I open the shell it works. This was already possible. But now I can close the shell (terminal) and it keeps working! Jul 24, 2021 at 15:53
  • 1
    I will try to insert gnome-terminal on my start-up preferences. So, I think it will work. Jul 24, 2021 at 16:05
  • OK then this looks like a case of just adding gnome-terminal to your startup apps.
    – Thomas Ward
    Jul 24, 2021 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.