Ubuntu – How to set an environment variable in a Unity session

environment-variablesunity

As a work-around to an issue with ibus, I'm trying to unset the variable $IBUS_ENABLE_SYNC_MODE. I have tried placing "unset IBUS_ENABLE_SYNC_MODE" in various places including:

  • .profile
  • .bashrc
  • /etc/environment
  • as a startup application

However, none of this is reflected in applications launched in Unity; for example, when I launch a terminal from Unity the result is:

~$ echo $IBUS_ENABLE_SYNC_MODE
1

Where should I set this variable so that Unity sources it properly?

Edit: The reason why my attempts are not working was because IBUS_ENABLE_SYNC_MODE is set internally by Unity code on start-up. So, short of modifying and recompiling Unity by hand, this does not have a solution.

Best Answer

The easy way to set personal environment variables for Unity (or any other X session) is to add them to the file $HOME/.xsessionrc. These variables are seen by everything launched in the session, via menus, GUIs, terminal windows, etc. For example, put this text in $HOME/.xsessionrc:

# File sourced by /etc/X11/Xsession, for setting environment variables, etc.
export FOOVAR=testing

Log out and back in, then from a shell window:

my-pc> echo $FOOVAR
testing

Tested under 12.04, using Unity. But this feature is implemented by the /etc/X11/Xsession script used by many types of desktop session, so it should work with any session type. See the Xsession man page.

Related Question