Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm looking for a way to set arbitrary environment variables for my graphical login on linux. I am not talking about starting a terminal and exporting environment variables within the terminal, because those variables only exist within that one terminal. I want to know how to set an environment variable that will apply to all programs started in my graphical session.

In other words, what's the Xorg equivalent of ~/.bash_login?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

You can always put them in .profile, so they should apply for any login.

Problems occur however, if a .bash_login exists: In that case, bash won't read .profile.

If you want your variables from .profile to apply both in bash and for other logins, don't use .bash_login! Put bash specific variables in .bashrc instead.

Or alternatively, include .profile from .bash_login

share|improve this answer
    
Thanks, .profile worked. –  Ryan Thompson Mar 18 '10 at 18:05
1  
Also, .profile is really nice because I can put any bash code I want to in it. So I cna add to existing environment variables, and do other stuff entirely. –  Ryan Thompson Mar 22 '10 at 22:09
1  
It seems that for KDE you need to put this in ~/.kde/env/ and end it with .sh. See the startkde manpage. –  Ryan Thompson Jul 11 '10 at 5:03
2  
Actually, this seems a bit more complicated. It depends on your choices distribution, desktop environment, and even your login shell. For Gnome on Ubuntu 10.04, you have to put your setup script in ~/.gnomerc, as shown in /etc/X11/Xsession.d/55gnome-session_gnomerc.KDE reads the profile script for whichever shell is your login shell. If SHELL=bash, then it reads ~/.profile. If SHELL=zsh, then it reads ~/.zprofile. I don't know what it does for other shells. –  Ryan Thompson Aug 27 '10 at 19:20

My .profile does more than just set environment variables so I've split off the environment setting tasks to a .setenv file which only sets the environment. To get it to set the environment for X11 on Debian, I added a .xsessionrc in my home with:

. ~/.setenv

The file that causes .xsessionrc to be sourced is /etc/X11/Xsession.d/40x11-common_xsessionrc.

Using the files that bash uses to set its environment did not do what I want. Sure, if I started a bash shell in X11, I'd get the environment I wanted. However, I need to have my PATH set so that my desktop environment will run the software I want. For instance, I often use custom versions of Firefox, installed outside the usual paths. I want my desktop environment to start the proper version rather than use whatever it can find on the default paths. To do this, PATH must be set before the desktop environment starts.

share|improve this answer

Xorg itself doesn't have one, since it doesn't start your programs - it would be whatever display manager (gdm, xdm, xinit, startx, etc.) or session manager (gnome-session, KDE, etc.) you use, since those are the parents of your desktop session processes. Unfortunately, there's a variety of those, each with different startup scripts/dotfiles, so there is no one-size-fits-all answer. (Under X's client/server model, the X server may not even be on the same machine as the clients, and it's often running as root instead of you, so is the wrong place for settings like environment variables.)

share|improve this answer
    
I know that Xorg itself isn't what I want to look at. I just want to know how to set my environment variables in my X session. –  Ryan Thompson Mar 19 '10 at 19:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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