How do I set an environmental variable for a GNOME session?
Solution 1:
It could be that the SDL_AUDIODRIVER variable is being unset somewhere. One strategy I use for problems with things related to startup scripts is to put in debug echo statements that is simple to enable/disable by creating/deleting a file. You could start by adding
debug_msg() {
test -f $HOME/.debug && echo "$@" 1>&2
}
debug_msg "running ~/.bashrc ($0), SDL_AUDIODRIVER = '$SDL_AUDIODRIVER'"
to .bashrc, .bash_profile, .profile and /etc/profile to see what value it has and if/where it is changing.
Solution 2:
https://help.ubuntu.com/community/EnvironmentVariables talks about four places where we can set the environment variables:
~/.pam_environment
- […] It is not a script file, but rather consists of assignment expressions, one per line. […] requires a re-login in order to initialize the variables. […]~/.profile
- This is probably the best file for placing environment variable assignments, since it gets executed automatically by the DisplayManager during the start-up process desktop session as well as by the login shell when one logs-in from the textual console.~/.bash_profile
or~/.bash_login
- If one of these file exist, bash executes it rather then "~/.profile" when it is started as a login shell. (Bash will prefer "~/.bash_profile" to "~/.bash_login"). However, these files won't influence a graphical session by default.~/.bashrc
- Because of the way Ubuntu currently sets up the various script files by default, this may be the easiest place to set variables in. The default configuration nearly guarantees that this file will be executed in each and every invocation of bash as well as while logging in to the graphical environment. However, performance-wise this may not be the best thing to do since it will cause values to be unnecessarily set many times.
http://userbase.kde.org/Session_Environment_Variables/en suggests this place for KDE:
KDE will execute any script it finds in
$HOME/.kde/env
whose filename ends in.sh
, and it will maintain all the environment variables set by them. It is important that any variable you want to set must be also exported.
https://help.ubuntu.com/community/ComposeKey#XIM suggests modifying ~/.gnomerc
or ~/.Xsession
.
Solution 3:
Create a .gnomerc
file in your $HOME which is a shell script (like .bashrc
) which sets all the variables you want.