echo %JAVA_HOME% returns %JAVA_HOME%
Asked Answered
H

13

69

When I do

echo %JAVA_HOME% 

it returns %JAVA_HOME% on windows 10 what did I do wrong?

Heighten answered 9/7, 2018 at 10:11 Comment(7)
Then it is possibly not set at all.Koblas
so what do I have to doHeighten
To confirm this, you can type in set and see if JAVA_HOME=something shows up in the results (it probably won't).Toreador
it works what nowHeighten
Please insert screenshot from your environment variablesSchroer
Had the same issue, restarting the CMD worked for me!Viaticum
you can try this theserverside.com/feature/…Pickar
L
71

If you are sure that you have set them properly, you can print your environment variables like JAVA_HOME using any of the below methods in Windows 10.


  1. Windows Command prompt ( cmd.exe )

    C:\>echo %JAVA_HOME%
    C:\Program Files\Java\jdk1.7.0_80
    

  1. Git Bash within windows, you need to use the bash format

    user12231@TP-UN103 MINGW64 /c
    $ echo $JAVA_HOME
    C:\Program Files\Java\jdk1.7.0_80
    

  1. From the conversation, it looks like you are using Windows 10 powershell.
    To print the environment variable in windows powershell, use one of the following commands as below

    PS C:\>Get-ChildItem Env:JAVA_HOME
    
    Name                           Value
    ----                           -----
    JAVA_HOME                      C:\Program Files\Java\jdk1.7.0_80
    

    or

    PS C:\> echo $env:JAVA_HOME
    C:\Program Files\Java\jdk1.7.0_80
    

    You can refer the Powershell documentation here.

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-6#displaying-environment-variables


Lath answered 15/10, 2018 at 21:56 Comment(2)
That's how I wish an answer to be! Mentions possible cases, discerns user-specific problem, examples and relevant link to documentation.Rabbinism
In PS (powershell) without echo, just giving $env:JAVA_HOME will also gives the output of set Java_home variable value. First preference with the User level declaration (to be noted for any corporate systems, where the system level env variables are protected from edits)Duplessis
U
34

There is high possibility that you used the Windows10 PowerShell terminal unknowingly instead of the standard windows command prompt.

In a standard Windows command prompt, when you type the below command, you would get the JAVA_HOME path as expected.

echo %JAVA_HOME%

Upon issuing the same command in PowerShell you would see %JAVA_HOME% written out.

PowerShell does things differently. In this case to output environment variables, you need to use

echo $env:JAVA_HOME

Additional tip: To print all environment variables dictionary use

dir env:
Uintathere answered 27/2, 2019 at 9:11 Comment(1)
Thanks... surely this is the most useful answer to the OP, as it provides a solution that helps achieve what they're trying to achieve by trying echo %JAVA_HOME%Rupee
C
8

In windows, Open powershell and try this command

echo $env:JAVA_HOME

Or if you have Git Bash installed then try

echo $JAVA_HOME
Campobello answered 8/8, 2022 at 2:40 Comment(0)
H
6

The syntax depends on the shell/terminal you are using. Try

echo $JAVA_HOME

this is the syntax for bash, for instance if you are using Git Bash to run your commands.

Houri answered 9/7, 2018 at 10:15 Comment(0)
B
3

For Windows Powershell use

$env:JAVA_HOME

For Windows Command Prompt use

echo %JAVA_HOME% 
Becket answered 4/4, 2022 at 6:22 Comment(0)
H
2

If you just added the System Variable you need to reboot for System to read it

if you are using an classic cmd command "echo %JAVA_HOME%" in windowsJAVA is fine

Hexamethylenetetramine answered 31/5, 2019 at 9:40 Comment(0)
P
1

Your command is correct for a windows 10 machine. And the result tells us, that this variable is not set. You can look for the settings for the environment variables in your start menu. You'll see settings for other variables like Path, TEMP and so on. There you can add JAVA_HOME (here without %). The path would be like this (from my pc): C:\Program Files\Java\jdk1.8.0_161

Protein answered 9/7, 2018 at 11:7 Comment(0)
P
1

It prints "JAVA_HOME" because you didn't set JAVA_HOME variable or you have typo in variable name. Just go to your environment variables settings and check if it's correct. If you don't have JAVA_HOME there just look at this question: How to set JAVA_HOME

Peralta answered 9/7, 2018 at 11:9 Comment(0)
S
0

I'm not sure, but i thought you need $ for Environment Variables.

Try: echo $JAVA_HOME

Sandbox answered 9/7, 2018 at 10:15 Comment(2)
i'm on windows 10Heighten
try it in the Bash (Command-Line) or try SET JAVA_HOME--> #5327995Sandbox
G
0

I know this answer is well overdue, but after hours of searching, it solved the problem for me.

Reinstall everything (git, jdk/jre, potentially maven), but when you do, leave EVERYTHING as its default value. Do not change any of the settings, DO NOT CHOOSE A SPECIFIC SAVE LOCATION that is convenient for you, etc. Leave everything as their default values.

Turns out, git is particularly rigid when it comes to flexibility, and it doesn't play well if you change the install location. When I was installing git, I changed the save location. I had been installing and practicing a bunch of new tools, and I wanted to have them all in one isolated spot. Just goes to show that the default way is usually the best way.

Grice answered 12/8, 2018 at 17:19 Comment(0)
G
0

i think u have installed jre, install jdk, your problem should be solved.

Gayomart answered 29/9, 2022 at 18:45 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Hover
A
0

Check that you've added JAVA_HOME variable in a corresponding block. If wrong, add in the bottom block and restart Windows.

enter image description here

Athelstan answered 19/10, 2022 at 9:20 Comment(1)
If you set it as a user variable, it's only available to the current user. If you set it as a system variable, it's available for all usersBooze
G
0

A mistake I did was that I set the user variables for the wrong account.

When searching to edit the system variables, Windows might ask you to confirm you are an admin. If you then enter your password for the administrator, the user variables are shown for the corresponding admin account, not the user account which you might currently be logged into.

Hence, be careful when adding the variables for only a user and double-check for which user you are adding the variables.

user variables for a PcGuestAccount

user variables for a PcAdminAccount, even though one is logged in with the guest account

Girondist answered 31/10, 2023 at 19:24 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Rosenquist

© 2022 - 2024 — McMap. All rights reserved.