1). For Windows
Step 1: Download Java
Visit the Java Download Page: Link
Select the Latest Java Development Kit (JDK)[JDK 25]LTS for Windows.
Download the installer (.exe file).
Step 2: Install Java
- Run the Downloaded .exe file.
- Follow the installation wizard steps:
Accept the license agreement.Choose an installation directory (default is usually fine). - Click Finish
Step 3: Set the PATH Environment Variable
- Open the Start Menu and Search for Environment Variables
- Click Edit the system environment variables.
- In the System Properties window, Click the Environment Variables button.
- Under System Variables, find and select the Path variable, then click Edit. If not available create one
- Add the following to the list of paths:
C:\Program Files\Java\jdk<version>\bin (Replace <version> with the installed JDK version number). - Click OK to save changes.
Step 4: Verify Installation.
- Open Command Prompt.
- Run the command:
java -version
If Java is installed correctly, it will display the installed version.
2). For macOS
Step 1: Download Java
- Visit the Java Download page: Link
- Select the latest JDK for macOS.
- Download the .dmg file.
Step 2: Install Java
- Open the downloaded .dmg file.
- Follow the installation prompts:
- Drag the Java installer to the Applications folder.
- Once the installation is complete, Java will be installed in
/Library/Java/JavaVirtualMachines/.
Step 3: Set the PATH Environment Variable
- Open the Terminal application.
- Edit the ~/.zshrc or ~/.bash_profile file (depending on your shell): nano ~/.zshrc
- Add the following line at the end of the file:
export
PATH=$PATH:/Library/Java/JavaVirtualMachines/jdk <version>/Contents/Home/bin (Replace <version> with the installed JDK version). - Save the file and reload it:
source ~/.zshrc
Step 4: Verify Installation
- Open the Terminal.
- Run the command:
java -version
If Java is installed correctly, it will display the installed version.
3). For Linux
Step 1: Download Java
- Open your browser and visit the Java Download page: Link
- Select the latest JDK for Linux.
- Download the .tar.gz file.
Step 2: Install Java
- Open the Terminal.
- Navigate to the directory where the .tar.gz file was downloaded:
cd /path/to/downloaded/file - Extract the file:
tar -xvzf jdk-<version>.tar.gz - Move the extracted folder to /usr/local/:
sudo mv jdk-<version> /usr/local/
Step 3: Set the PATH Environment Variable
- Open the ~/.bashrc or ~/.zshrc file:
nano ~/.bashrc - Add the following line at the end of the file:
export PATH=$PATH:/usr/local/jdk-<version>/bin - Save the file and reload it:
source ~/.bashrc
Step 4: Verify Installation
- Open the Terminal.
- Run the command:
java -version
If Java is installed correctly, it will display the installed version.
Top comments (0)