({{, (RefLink[SetEnvironment, paclet:ref/SetEnvironment])["var"->value] 
sets the value of an operating system environment variable.}, {, (RefLink[SetEnvironment, paclet:ref/SetEnvironment])[{"var"->value,…}]
sets values for several environment variables.}})

OpenersNotesSection(Spacer1)Details

An environment variable defined in the current session is accessible within this session or in the child processes spawned by the Wolfram System, for example, when using (RefLink[Run, paclet:ref/Run]) or (PackageLink[CreateLibrary, paclet:CCompilerDriver/ref/CreateLibrary, CCompilerDriver Package Symbol]).

Values of environment variables, or merely their existence in the environment, may affect the behavior of certain Wolfram Language functions or child processes.

The value or the existence of a defined variable is not preserved when the Wolfram System is terminated or restarted.

If the variable "var" did not exist in the environment, its name is added to the environment with the associated "value".

If the variable "var" already existed in the environment, its value is replaced with "value".

Setting "var"->(RefLink[None, paclet:ref/None]) removes the variable and its definition from the environment. If "var" did not previously exist, it will not be created.

Setting "var"->"" does not remove the variable from the environment, but merely sets its value. If "var" did not previously exist, it will be created.

OpenersPrimaryExamplesSection(Spacer1)Examples  (5)

OpenersExampleSection0(Spacer1)Basic Examples  (5)

Set the HOME environment variable:

SetEnvironment["HOME"->"/Users/adamg/"]

Set multiple variables:

SetEnvironment[{"VAR1"->"1","VAR2"->"2"}]

Get the values of variables:

GetEnvironment["HOME"]

Environment["HOME"]

GetEnvironment[{"HOME","VAR1","VAR2"}]

Unset the variable or remove the variable from the environment:

SetEnvironment["VAR1"->None]

GetEnvironment[{"HOME","VAR1","VAR2"}]

Environment variables are accessible to child processes. On Windows:

SetEnvironment["FOO"->"1"]
Import["!echo %FOO%","Text"]

On Unix:

SetEnvironment["FOO"->"1"]
Import["!echo $FOO","Text"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[GetEnvironment, paclet:ref/GetEnvironment])  ▪  (RefLink[Environment, paclet:ref/Environment])  ▪  (RefLink[Run, paclet:ref/Run])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Low-Level System Optimization, paclet:guide/LowLevelSystemOptimization])}})}})