Java Installation
Step-by-Step Java Installation
1. Choosing the Java Distribution
Java has various distributions; each serves specific purposes. Some popular ones include -
Oracle JDK: Official distribution from Oracle. Free for personal use, but commercial use may require licensing.
OpenJDK: Open-source and widely used for development and production.
Others: Amazon Corretto, Azul Zulu, Liberica JDK, AdoptOpenJDK (now Eclipse Temurin).
2. Downloading Java
Visit the appropriate JDK provider’s website -
OpenJDK: https://jdk.java.net
Other distributions as per preference.
Download the appropriate version (e.g., JDK 8, JDK 11, JDK 17, or later).
LTS (Long-Term Support) versions (e.g., JDK 8, JDK 11, JDK 17) are preferred for production.
Latest versions for experimental or cutting-edge features.
3. Installation on Different Operating Systems
Windows
Run the downloaded installer (
.exe
).Follow the prompts in the installation wizard
Accept the license agreement.
Choose an installation directory or leave it as the default.
The installer will copy files and set up the Java Runtime Environment (JRE) alongside the JDK.
Set Environment Variables
Open System Properties → Environment Variables.
Add or update the following:
JAVA_HOME: Set to the JDK installation path (e.g.,
C:\Program Files\Java\jdk-17
).PATH: Add
%JAVA_HOME%\bin
to PATH to accessjava
andjavac
commands from any terminal.
Verify installation
Open Command Prompt.
Run
java -version
andjavac -version
.
macOS
Install via the
.dmg
package or use a package manager like HomebrewIf using the downloaded
.dmg
Double-click the file and follow installation steps.
The installer sets up JDK in
/Library/Java/JavaVirtualMachines/
.
Set Environment Variables
Edit
~/.zshrc
or~/.bash_profile
:
Verify installation
Run
java -version
andjavac -version
in the terminal.
Installing Multiple JDK Versions
Download multiple versions (e.g., JDK 8, JDK 11, JDK 17) side-by-side and update the java path as needed.
Use tools like SDKMAN to manage multiple JDKs
Java Program to check if Java is installed on the computer
Java Installation Best Practices
Use LTS versions for stability in production.
Regularly update to the latest security patches.
Install only the necessary tools (e.g., avoid JDK if only JRE is required).
Automate installation in CI/CD pipelines using scripts or tools like Docker
Last updated
Was this helpful?