11

How do I set Windows environment variables permanently?

I see that the Windows environment variables are reset when you close the command window. I want to set them permanently, so that I don't have to repeat the task every time I use the CLI.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
CleanX
  • 1,158
  • 3
  • 17
  • 25

2 Answers2

10

This can also be achieved from a command prompt. The following example sets a variable at the user level:

SETX variable_name value

For machine level, elevation is required:

SETX variable_name value /m
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
  • 2
    If you use this for updating %PATH%, this will cut it down to 1024 chars and potentially delete every path behind that range. So take care when using. – Gary Klasen Jan 22 '21 at 07:40
9

Right click on Computer, Advanced system settings, select Advanced tab and click Environment variables.

Note: once you modify the environment variables, you will have to restart your applications, including CLI.

user1764961
  • 673
  • 7
  • 21
  • For windows 8 users: Typing "Control Panel\All Control Panel Items\System" in the file explorer exposes the "Advance System Settings" link. – amalgamate Jan 06 '16 at 20:30
  • This may [depend on the version of Windows](https://stackoverflow.com/questions/9546324/adding-a-directory-to-the-path-environment-variable-in-windows/72341522#72341522). What version is it? – Peter Mortensen Dec 28 '22 at 18:50