Easier way to change environment variables in Windows 8?

27

17

Possible Duplicate:
What are PATH and other environment variables, and how can I set or use them?

I know that I can edit my environment variables in windows 8 by going to

Start -> All Apps -> Control panel -> System -> 
    Advanced System Settings -> Advanced -> Environment variables.

But honestly, this is ridiculously complex.

Is there an easier way to change environment variables in Windows 8?

For instance if I just want to append new folder to PATH, it is really annoying to go through all these steps. The UI also sucks, because it is really painful to edit long variable values with the small text input.

Requirement 1: I need the changes to persist (e.g. when I use set in console the changes are lost when I close the console)

Requirement 2: I'd prefer a solution that doesn't involve installing extra pieces of software, since this is the kind of problem that I stumble across every time I configure a new Windows box.

jsalonen

Posted 2012-11-07T19:04:41.903

Reputation: 7 143

Question was closed 2012-11-07T20:59:02.633

Nice post about the subject: http://www.windows-commandline.com/set-path-command-line/

– Royi – 2016-08-14T20:44:51.830

Answers

32

Have you explored the set and setx command? With them you can set a persistent variable. Moreover, the value will be applied immediately, not after the next logon.

Example of windows SET command:

Print the PATH environment variable:

C:\Users\Charity>echo %PATH%
C:\windows\system32;C:\windows and space;C:\foobar

Use set command to set the PATH variable

C:\Users\Charity>set PATH=%PATH%;C:\epicpath
C:\Users\Charity>

The above command only applies to the current window and the change is lost when the cmd window is closed.

C:\Users\Charity>echo %PATH%
C:\windows\system32;C:\windows and space;C:\foobar;C:\epicpath

Example of windows SETX command:

Print the PATH environment variable:

C:\Users\Charity>echo %PATH%
C:\windows\system32;C:\windows and space;C:\foobar

Use setx to set the environment variable:

C:\Users\Charity>setx PATH "%PATH%;C:\zombiepoke"
SUCCESS: Specified value was saved.

Close and re-open cmd terminal, then run:

C:\Users\Charity>echo %PATH%
C:\windows\system32;C:\windows and space;C:\foobar;C:\zombiepoke

You have to be careful with double quotes. If you let quotes get into your path variable it might break something. However they are necessary for specifying addendums to the original %PATH%.

Yury

Posted 2012-11-07T19:04:41.903

Reputation: 421

4No args "setx" sets the variable in user context only. To set in system context use "setx /M". Not being aware of this may confuse you since "echo %PATH%" will show the system and user values concatenated. – Vituel – 2014-08-23T15:20:47.943

Note, you have to restart the shell after you make this change for it to take effect. – Doug – 2014-09-14T21:34:57.277

minor note: set path =~ echo %PATH% [set path shows also the value of PATHEXT] – gerryLowry – 2015-12-06T22:04:29.960

Is there a way to add something to the path until the next restart? Or if I work on MATLAB and use set, can I make sure it holds for the MATLAB session? – Royi – 2016-08-14T20:13:25.127

1Thanks for the tip! I tried setx PATH=%PATH%;;C:\test but I get syntax error :( – jsalonen – 2012-11-07T19:22:26.197

2There is no = sign when using setx. Do setx /? – EBGreen – 2012-11-07T19:33:32.573

10

Set Environment variable in Windows 8.

You can access the advanced system setting by right clicking Computer in a file-explorer and going to properties.

This is same as older versions of windows. You can also set environment variables from command line as given here :

What are PATH and other environment variables, and how can I set or use them?

vishesh

Posted 2012-11-07T19:04:41.903

Reputation: 972

4

I change them in Powershell. For instance to add a folder to the PATH variable, open powershell then:

$newPath = $env:Path + ';C:\Temp'
[Environment]::SetEnvironmentVariable('Path', $newpath, 'Machine')

That would change it for all users. To change it just for the user running the command, change that last parameter to 'User'. Or to just change it temporarily in this session:

$env:Path += ';C:\temp'

EBGreen

Posted 2012-11-07T19:04:41.903

Reputation: 7 834

great! how do you do the $env:Path + ';C:\Temp' concatenation at the command prompt? Set & Setx solutions here explain how to set the entire path at command prompt, but none explain how to APPEND something to the existing path. – johny why – 2014-06-22T18:57:47.320

Here's how to APPEND something to the existing path at a command prompt. /M is used to alter the SYSTEM variable, rather than the USER variable. Quotes are used since "My Folder" contains spaces: setx PATH "%PATH%;C:\My Folder" /M – johny why – 2014-06-22T19:39:19.073

Only problem with using command prompt is 255 character limit, and the system PATH is likely to exceed that (especially if you're appending more directories). Therefor, Powershell is the way to go (i could be wrong, but i believe there's no character-count limitation with Powershell). – johny why – 2014-06-22T20:40:56.437

3

It's pretty easy on the command line:

set MyVar=HelloWorld

(to get to the command line, type cmd from the start screen>.)

To view a variable:

echo %MyVar%

Use setx to permanently set a variable. The syntax is slightly different. Try looking here, or there's lots of other sites out there that will tell you how to use it.

ACarter

Posted 2012-11-07T19:04:41.903

Reputation: 1 044

Is there a way to set the variable just until the next restart? Otherwise, if I use set from another program (Let's say OS command from Python or MATLAB), will it hold as long the session of the program is open? – Royi – 2016-08-14T20:23:13.003

Yeah thanks man I know this already, but the problem is that if you do changes in this way they don't persist -- i.e. when I close and reopen the command-line the variables are reverted to defaults. Updated my question to reflect this -- sorry. – jsalonen – 2012-11-07T19:11:47.957

Do you know if I can do a set that will persist? – jsalonen – 2012-11-07T19:19:29.693

1setx is for permanent changes – EBGreen – 2012-11-07T19:20:37.850