The Computer Oracle

How can I set environment variables for a graphical login on linux?

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Future Grid Looping

--

Chapters
00:00 How Can I Set Environment Variables For A Graphical Login On Linux?
00:34 Accepted Answer Score 14
01:05 Answer 2 Score 0
01:43 Answer 3 Score 6
02:47 Thank you

--

Full question
https://superuser.com/questions/121261/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #xorg #environmentvariables

#avk47



ACCEPTED ANSWER

Score 14


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




ANSWER 2

Score 6


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.




ANSWER 3

Score 0


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.)