Terminal command for changing ibus keyboard layout?

Actually, ibus provides an system tray applet.

  1. Run ibus-setup
  2. On General tab, Check Show icon on system tray
  3. On General tab, confirm you have shortcut
  4. On Advanced tab,Uncheck Use system keyboard layout

ibus applet

It's more related to xkb than to ibus (but I am not sure I completely understand the intricacy of the keyboard handling, as you can see in this post of mine) but you can detect the current configuration with

[romano:~] % setxkbmap -query
rules:      evdev
model:      pc105
layout:     es,gb
variant:    standard_tlde,
options:    caps:none,compose:caps,terminate:ctrl_alt_bksp

note it down, and then use

setxkbmap -layout es -variant standard_tlde -option caps:none,compose:caps,terminate:ctrl_alt_bksp

that you can associate to a key. It should work in all Ubuntu flavors, at least X11-based (no idea about wayland).