I'm trying to access my environment variables in Mathematica, but I get a Failed result every time. For example:

$ echo $USER

but in Mathematica I do:

(* $Failed *)

Is there a preference that I need to set? Is my Mathematica installation messed up? Please advise.

  • $\begingroup$ Please try GetEnvironment[] $\endgroup$ Mar 5, 2015 at 18:10
  • $\begingroup$ As @halirutan exposed, I didn't capitalize correctly. Now what do I do when I'm expecting an environment variable, but don't see it in Mathematica when I use GetEnvironment? $\endgroup$
    – jlconlin
    Mar 5, 2015 at 18:21

1 Answer 1


Your environment variable is all upper-case!


If you have capitalized your variable correctly and you still don't see it in Mathematica, then this is a problem of your window environment. Mathematica is a graphical program which doesn't get the same environment as you have in a terminal.

First you should try to start Mathematica from the very same terminal that knows about your variable. If this works, then you need to change the environment when you start Mathematica from an icon.

This procedure is different for every operating system. In Linux, you use something like this in your icon launcher:

env WEIRD=1 /usr/local/bin/Mathematica

and you will have WEIRD in your running Mathematica.

In OSX, you use launchctl for this.

  • $\begingroup$ Of course this is the answer. Now what do I do if I'm expecting a variable (i.e., I can see it in bash) but Environment doesn't see it. (I double checked that I have the right capitalization!) $\endgroup$
    – jlconlin
    Mar 5, 2015 at 18:16
  • $\begingroup$ @Jeremy See my update. $\endgroup$
    – halirutan
    Mar 5, 2015 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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