To set a temporary or 'per session' environment varible from a command line you can use:
set ‹var name›=‹value>
Make sure your spacing is exactly as shown above, if you add a space between the equal sign the command will fail.
Check: Link for a nice tutorial and info on environment variables.
Answer from akseli on Stack ExchangeTo set a temporary or 'per session' environment varible from a command line you can use:
set ‹var name›=‹value>
Make sure your spacing is exactly as shown above, if you add a space between the equal sign the command will fail.
Check: Link for a nice tutorial and info on environment variables.
If you are using PowerShell, then you need to use the $env prefix for creating an environment variable.
Here's an example:
$env:<var name> = '<value>'
Videos
Here’s how I’ve done it many times via command line. Run setx /? at a cmd prompt for all the options. /M makes it a system wide variable.
Ex.
ORACLE_HOME is the variable name.
The C:\ path is the value of the variable.
SETX ORACLE_HOME C:\Oracle\product\11.2.0\instantclient_11_2 /M
Is there a command line I can use to set PC and Server environment variables? I have several I have to type in often. It would be nice to write a script to enter them for me.
» pip install python-dotenv
Starting with Windows Vista, the panel can be displayed from the command line (cmd.exe) with a
rundll32 sysdm.cpl,EditEnvironmentVariables
It is from here.
I recommend this: Open the "Run" prompt → type "SystemPropertiesAdvanced". You will be on the Advanced tab of the System Properties window. From here it's easy. I feel this is an easier command to remember than the command prompt's and a good shortcut.
Windows 7: Start menu → in the search bar, type "system variables" and Enter. You will have the Advanced tab of the system properties window open.
Windows 8 and later: Simply type the above in the search box in the task bar.
Note: After seeing lots of comments about setting environment variables without administrator rights in Windows 10, I think I have found a way. I was not administrator and could use PowerShell.
PowerShell method
You can list all environment variables with: Get-ChildItem Env:.
To get the value of a specific variable: $Env:PATH, where PATH is the name of the variable.
To set a variable: [Environment]::SetEnvironmentVariable("PATH", "C:\TestPath", "User"), the first parameter is the name of the variable, the second is the value, the third is the level of.
There are different ways to work with environment variables and certain quirks with them in PowerShell so consult the link for details.
Old method (no longer available in newer Windows 10 updates, use PowerShell or see other answers)
Go into Settings and click on System.

Then on the left side click About and select System info at the bottom.

In the new Control Panel window that opens, click Advanced system settings on the left.

Now in the new window that comes up, select Environment Variables... at the bottom.

Still the same as ever: It’s in the old-style control panel’s “System” thingy. You can reach it with WinBreak or by right-clicking the Start button.
From there, select “Advanced system settings” → “Environment Variables”.
Or you can do it the hard way and find some other entry point to the old-style control panel, like the Network and Sharing Center or the Desktop folder(!).