How to Install the Latest Java Version on Windows¶
This guide provides step-by-step instructions for installing the latest version of Java on a Windows machine, covering both cases where you have administrative privileges and when you do not. It also includes details on updating the environment variables after installation.
1. Check Your Current Java Version¶
Before installing Java, check if you already have a version installed. Open Command Prompt (cmd) or PowerShell and type:
java -version
2. Download the Latest Java Version¶
Visit the official Oracle JDK download page: - Oracle Java Downloads - Alternatively, you can use OpenJDK: Adoptium
Choose the appropriate JDK installer for Windows.
3. Installing Java with Admin Rights¶
If you have administrative privileges, follow these steps:
1. Run the Installer: Double-click the .exe
installer and follow the prompts.
2. Select Installation Path: By default, Java installs in C:\Program Files\Java\jdk-<version>
.
3. Complete Installation: Click ‘Next’ and finish the installation.
Updating Environment Variables (Admin Method)¶
- Open the Start Menu, search for
Environment Variables
, and select Edit the system environment variables. - Click Environment Variables.
- Under System Variables, find
Path
, select it, and click Edit. - Click New and add the Java
bin
directory path (e.g.,C:\Program Files\Java\jdk-<version>\bin
). - Set the
JAVA_HOME
variable: - Click New under System Variables.
- Set
JAVA_HOME
as the variable name andC:\Program Files\Java\jdk-<version>
as the value. - Click OK to save changes.
- Open a new Command Prompt or PowerShell window and type:
to verify the installation.
java -version
4. Installing Java Without Admin Rights¶
If you do not have administrative privileges, follow these steps:
- Download the ZIP version of the JDK from Adoptium or Oracle.
- Extract the ZIP to a folder where you have write access, e.g.,
C:\Users\YourUsername\Java\jdk-<version>
.
Updating Environment Variables (User Method)¶
- Open Start Menu, search for
Environment Variables
, and select Edit the environment variables for your account. - Under User Variables, find
Path
, select it, and click Edit. - Click New and add the Java
bin
directory path, e.g.,C:\Users\YourUsername\Java\jdk-<version>\bin
. - Set
JAVA_HOME
: - Click New under User Variables.
- Set
JAVA_HOME
as the variable name andC:\Users\YourUsername\Java\jdk-<version>
as the value. - Click OK to save changes.
- Restart Command Prompt or PowerShell and verify by running:
java -version
5. Running Java Without Setting Environment Variables¶
If you do not want to set up environment variables, you can still run Java manually from the extracted folder:
1. Navigate to the extracted JDK folder where java.exe
is located.
2. Open Command Prompt or PowerShell and type the full path to the Java binary:
C:\Users\YourUsername\Java\jdk-<version>\bin\java -version
C:\Users\YourUsername\Java\jdk-<version>\bin\java -jar C:\Users\YourUsername\Downloads\runsomething.jar
./Downloads/java -jar runsomething.jar
6. Verifying Java Installation¶
After setting the environment variables, confirm that Java is correctly installed by running:
java -version
Additional Notes¶
- If multiple versions of Java exist on your system, ensure the correct one appears first in the
Path
variable. - To switch Java versions, adjust the
JAVA_HOME
variable accordingly. - Consider using a Java version manager like
jEnv
(for Windows Subsystem for Linux) orSDKMAN!
(on Windows via WSL) for managing multiple Java versions efficiently.