2 ways to List environment variables in command line windows
Environment variables are used to store the folder or file path with variable names.
Setting environment variables is required when installing java, tomcat, or derby applications.
The commands will not run as expected if environment variables are not set.
It’s difficult for a developer to tell whether environment variables are set or not from a command line in Windows.
This article explains different ways to print Windows environment variables from a command line.
- set command
- Get-ChildItem Env
set command to get environment variable list
set command in windows used to set the environment variables for command line scope
Syntax
set VARIABLE=path/value
Here’s an example of setting JAVA HOME to the JDK route.
set JAVA_HOME=c:\JDK1.9
`SET command also lists all environment variables.
Here simple set command prints all environment variables configured already
C:\>set
ALLUSERSPROFILE=C:\ProgramData
ANDROID_HOME=A:\android\sdk
ANT_HOME=A:\Java\apache-ant-1.10.0
APPDATA=C:\Users\Kiran\AppData\Roaming
ChocolateyInstall=C:\ProgramData\chocolatey
ChocolateyLastPathUpdate=132329753418192180
ChocolateyToolsLocation=C:\tools
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=KIRAN
ComSpec=C:\WINDOWS\system32\cmd.exe
DERBY_HOME=C:\db-derby-10.14.2.0-bin
DriverData=C:\Windows\System32\Drivers\DriverData
GOOGLE_API_KEY=no
if you have a long list of environment variables, it is difficult to see on a single page,
Then, You can output all environment variables to a file or can view by page by page.
The below command uses pipe with more list out environment variables one page at a time, on clicking enter keystroke, navigate page by page to end of the result.
set | more
How do you print the environment variable list to a text file?
with >
and set command, It prints the list to the output file.
Here is an example of usage
C:\>set > output.txt
This will output the environment variables list to the output.txt file.
Please note that administration permission is required to run this command, Otherwise, it gives Access is denied.
If you want to filter the list, you can use the below command with the keyword
C:\>set derby
DERBY_HOME=C:\db-derby-10.14.2.0-bin
Get-ChildItem Env to list environment variables with Windows PowerShell
It is another approach to print environment variables using Windows PowerShell.
First, go to windows + Run(R), type Windows PowerShell It will open PowerShell.
Run the below command to list the environment variable
Get-ChildItem Env:
Conclusion
It solves a problem for a developer to know the environment list for java/derby/maven installation.