A nice package that helps with setting up the environment is exec-path-from-shell
(at MELPA or https://github.com/purcell/exec-path-from-shell). As the name suggests it sets the PATH variable to a more useful value, but it is also able to set any number of environment variables. I use it like this:
(when (and (memq window-system '(mac ns))
(require 'exec-path-from-shell nil t))
;; (setq exec-path-from-shell-debug t)
(exec-path-from-shell-initialize)
(exec-path-from-shell-copy-envs '("LANG" "GPG_AGENT_INFO" "SSH_AUTH_SOCK"))
(message "Initialized PATH and other variables from SHELL."))
With these lines I get the same locale environment as in my plain terminal sessions. A more simple variant of the above, that will throw errors if the library is not available is:
(require 'exec-path-from-shell)
(exec-path-from-shell-initialize)
(exec-path-from-shell-copy-envs '("LANG" "GPG_AGENT_INFO" "SSH_AUTH_SOCK")))
In order to check if an environment variable has found its way inside Emacs, call the function getenv
via M-x.
EDIT: As has been mentioned in the comments, you should double check that your environment variables, that should be imported by Emacs, are really available in a default shell. This can be check via env
(in the shell or terminal). If the variable is missing in the env output, it has to be exported from your shells init script (e.g. ~/.bash_login
or ~/.bashrc
).