If you don't have admin rights, use the below command to set environment variables for java using the command prompt
setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0"
setx PATH "%PATH%;%JAVA_HOME%\bin";
Modify the environment variable.
setx -m JAVA_HOME "C:\Program Files\Java\jdk1.8.0"
setx -m PATH "%PATH%;%JAVA_HOME%\bin";
Answer from Sathiamoorthy on Stack OverflowIf you don't have admin rights, use the below command to set environment variables for java using the command prompt
setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0"
setx PATH "%PATH%;%JAVA_HOME%\bin";
Modify the environment variable.
setx -m JAVA_HOME "C:\Program Files\Java\jdk1.8.0"
setx -m PATH "%PATH%;%JAVA_HOME%\bin";
Set the JAVA_HOME Variable
Windows 7 – Right click My Computer and select Properties > Advanced
Windows 8 – Go to Control Panel > System > Advanced System Settings
Windows 10 – Search for Environment Variables then select Edit the system environment variables

Click the Environment Variables button.
Under System Variables, click New.
In the Variable Name field, enter either:
JAVA_HOME if you installed the JDK (Java Development Kit)
or
JRE_HOME if you installed the JRE (Java Runtime Environment). In the Variable Value field, enter your JDK or JRE installation path .

Open Command Prompt as Administrator.
Set the value of the Environment variable to your JDK (or JRE) installation path as follows:
setx -m JAVA_HOME "C:\path_to_Java\jdk_version"
I get "JAVA_HOME is not set" error even though it exists in System Environment Variables
How do I set JAVA_HOME ?
Videos
You can set your JAVA_HOME in /etc/profile as Petronilla Escarabajo suggests. But the preferred location for JAVA_HOME or any system variable is /etc/environment.
Open /etc/environment in any text editor like nano or gedit and add the following line:
JAVA_HOME="/usr/lib/jvm/open-jdk"
(java path could be different)
Use source to load the variables, by running this command:
source /etc/environment
Then check the variable, by running this command:
echo $JAVA_HOME
Update
Usually most linux systems source /etc/environment by default. If your system doesn't do that add the following line to ~/.bashrc (Thanks @pje)
source /etc/environment
To set JAVA_HOME environment variable, do the following:
- Launch Terminal by pressing Ctrl+Alt+T on your keyboard.
- Enter the following command:
$gksudo gedit /etc/environment - Depending on where you installed your Java, you will need to provide the full path. For this example, I installed Oracle JDK 7 in the
/usr/lib/jvm/java-7-oracledirectory.
Scroll to the end of the file and enter the following:
JAVA_HOME=/usr/lib/jvm/java-7-oracle
export JAVA_HOME - Save your file and exit gedit.
- Lastly, reload the system PATH with the following command:
$. /etc/environment
The above method will save you the hassle in having to run the commands every time you log in to your computer.
I am following this tutorial for making a minecraft mod using IntelliJ and when i get to the point where you type
./gradlew genSources
into the terminal (at about 12:08) i always get
ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation.
I have tried deleting and reinstalling both Eclipse Adoptium and IntelliJ as well as going into the System Environment Variables and deleting the JAVA_HOME variable and creating it again with this file path: C:\Program Files\Eclipse Adoptium\jdk-21.0.5.11-hotspot, I have also edited the Path system variable to include %JAVA_HOME%\bin and so far I have experienced no change. I don't know much about programming or java but as far as I know your JAVA_HOME is supposed to be linked to a JDK, and as far as I can tell mine is so I don't know whats the problem
Hello! I'm very (very) new to programming. I'm following a tutorial by Kaupenjoe to make (what I thought would be) a very simple Minecraft mod. But when I get to the step in the tutorial at 12:30 and run the terminal command ./gradlew genIntellijRuns, I receive the following error message. I'm still trying to figure out how all of this works, so pardon my ignorance if this is a stupid question, but I cannot for the life of me find how to correct this error. Could anyone walk me through it, please?
ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the location of your Java installation.