Ubuntu – How to set environment variables in an Emacs session launched from Gnome Panel

bashemacsgnome-panel

My .bash_env file sets several environment variables, including PATH and EMAIL, but in an Emacs session launched from the Gnome Panel (command: "/usr/bin/emacs23 %F") these variables do not have the expected values. I've run into this problem before (see this blog post). I fixed it then by sourcing .bash_env in my .xsession file. Obviously, this is no longer working.

The variables are set properly if I manually launch Emacs from a terminal. Oddly, they aren't set if I change the panel launcher to execute Emacs in a terminal (I would think this would start Bash before starting Emacs).

How can I make sure the regular Bash environment is set up for the Emacs session?

Best Answer

Set the environment variables in ~/.profile (and source ~/.profile from ~/.xsession if you use a .xsession). That way they will be available everywhere, because they'll be set when you log in.

~/.bash_env is not the right place for environment variables (despite the name) . (Despite its existence (that's $BASH_ENV, right?) I've yet to find a good use for it.)

When you run Emacs in a terminal, it is a subprocess of the terminal emulator. There would be no reason to have a shell in between.