Is there a common way in which environment variables are accessed, stored, or used by the kernel?

There are built-in functions for querying and setting vars in the system environment, but there are also instances where environment variables seem to be mirrored by strings or list of strings stored in symbols, often prefixed by $:

$BaseDirectory (related to MATHEMATICA_BASE environment variable)

$UserBaseDirectory (related to MATHEMATICA_USERBASE environment variable)

In addition, the system sessions docs mention:

MATHKERNELINIT --> specifies command‐line options for the Wolfram Language kernel

MATHINIT --> specifies command‐line options for the Wolfram System front end

--- (edited to avoid misinformation) ---

@Szabolcs points out that $Path is not related to PATH, and others listed below do not generally correspond to OS environment variables:

$OperatingSystem, $System, $SystemID

$HomeDirectory, $InitialDirectory

$TemporaryDirectory, $TemporaryPrefix

A comment by @rhermans on this question piqued my interest in how these kinds of symbols are used when they seem to represent environment variables.

$TemporaryDirectory gives the main system directory for temporary files on your computer system. It's reporting a system variable, not defining where it should be.

Is it common to use a $var for "reporting the state" of an environment variable?

  • $\begingroup$ As demonstrated by @MichaelE2, you can set $TempDirectory to your liking. $\endgroup$
    – Yves Klett
    Commented Oct 21, 2014 at 8:49
  • 1
    $\begingroup$ These Mathematica variables are unrelated to environment variables. In particular $Path has an entirely different purpose and should not be confused with the system's PATH environment variable. $\endgroup$
    – Szabolcs
    Commented Oct 21, 2014 at 16:02

1 Answer 1


The Mathematica variables you mention are unrelated to any system environment variables. It is not correct to think that they mirror any system environment variables. The similar names (as well as the use of $ in Mathematica) are just accidental.

In particular, $Path has nothing to do with the system's PATH environment variable and serves an entirely different function. I thought this important to point out because people have confused these in the past which led to all kinds of trouble.

While it is true that Mathematica will be affected by certain environment variables, such as MATHEMATICA_USERBASE, there is no general correspondence between any $-variables in Mathematica and environment variables.

Regarding the use of $ in Mathematica: it is the only non-alphanumeric character that is allowed in identifier names. It is customary to name global constants as $... in Mathematica code, similarly to how it is customary to use lower-case names for non-public or user-defined symbols. This is just a convention, it does not indicate any relationship to environment variables.

  • $\begingroup$ Could you elaborate a little bit on what you mean by "serves a different purpose"? The usage message for $Path says: $Path gives the default list of directories to search in attempting to find an external file ... which sounds very similar the use case for the PATH environment variable. $\endgroup$
    – dionys
    Commented Oct 21, 2014 at 21:55
  • $\begingroup$ @dionys $Path tells Mathematica where to look for files when using Get within Mathematica, while PATH tells the operating system where to look for executable binaries. $\endgroup$
    – Szabolcs
    Commented Oct 21, 2014 at 22:07

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.