X11 – Setting PATH for X Apps

environment-variablesgnomepathx11

How can I set env variables so that KDE recognizes them?

How do you set the path in a non-shell environment (KDE)?

Unlike the above two questions, I want to know how to do this for GNOME. Or better yet, is there a method that is independent of the window manager. For the shell/terminal, I usually edit ~/.bashrc. Where can I place export statements so that environment variables are available for all X applications, no matter the window manager used?

Best Answer

The pam_env PAM module let's you set them either in /etc/environment or in ~/.pam_environment, depending on whether you want it for all users (system wide), or just your user (session-wide).

System-wide environment variables

Environment variable settings that affect the system as a whole (rather then just a particular user) should not be placed in any of the many system-level scripts that get executed when the system or the desktop session are loaded, but into

/etc/environment - This file is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line. Specifically, this file stores the system-wide locale and path settings.

Session-wide environment variables

Environment variable settings that should affect just a particular user (rather then the system as a whole) should be set into:

~/.pam_environment - This file is specifically meant for setting a user's environment. It is not a script file, but rather consists of assignment expressions, one per line.

Note: Using .pam_environment requires a re-login in order to initialize the variables. Restarting just the terminal is not sufficient to be able to use the variables.

See more at Ubuntu's wiki on Environment Variables.