set environment variable windows code example

Example 1: how to create env variable from cmd

set varname
set varname=value
set varname=
set

Example 2: windows echo environment variable

// In a Windows console (cmd)
// All environnement variables:
set
// A single one:
set MY_VAR
// Or:
echo %MY_VAR%

// Sets an environment variable called MY_VAR
set MY_VAR=hello
   
// Display
set MY_VAR
-> MY_VAR=hello
   
// Unset an environment variable
set MY_VAR=
   
// Display
set MY_VAR
-> Environment variable MY_VAR not defined

// Display the PATH environment variable
echo %PATH%
-> PATH=xxxxxxx

Example 3: set environment variable windows command line

setx EC2_CERT "%USERPROFILE%\aws\cert.pem"

Example 4: how to change environment variables in windows 10

Open the Start Search, type in “env”, and choose “Edit the system environment variables”:

Tags:

Java Example