Environment variables are used 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
Here’s an example of setting JAVA HOME to the jdk route.
SET commandalso list all environment variables
Here simple set command print 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 long list of environment variables, it is very difficult to see in a single page,
Then, You can output the all environment variables to file or can view by page by page
The below command using pipe with more list out environment variables one page at a time, on clicking enter keystroke, navigate page by page to end of result.
set | more
How do you print the environment variable list to text file?
> and set command, It prints the list to output file.
Here is an example usage
C:\>set > output.txt
This will output the environment variables list to output.txt file.
Please note that administration permission required to run this command, Otherwise it gives
Access is denied.
If you want to filter the list, you can use below command with keyword
C:\>set derby DERBY_HOME=C:\db-derby-10.14.2.0-bin
Get-ChildItem Env to list environment variables with windows PowerShell
This is an other approach to print environment variables using Windows PowerShell.
First, go to windows + Run(R), type Windows PowerShell This will open powershell
Run the below command to list environment variable
This solves an problem for developer to know the environment list for java/derby/maven installation.
Please subscribe and share it in social media.