Installation

How to Install Java on Windows, macOS, and Linux

A Step-by-Step Guide to Installing Java

Java is one of the most popular programming languages in the world, used for everything from web development to mobile apps and enterprise software. Whether you’re a developer or just need Java to run certain applications, installing it on your system is a straightforward process. In this guide, we’ll walk you through how to install Java on Windows, macOS, and Linux.


1. Installing Java on Windows

Step 1: Download the Java Development Kit (JDK)

  1. Visit the official Oracle JDK website or the OpenJDK website.
  2. Choose the latest version of the JDK (e.g., Java 21) and download the installer for Windows.

Step 2: Run the Installer

  1. Locate the downloaded .exe file and double-click it to start the installation.
  2. Follow the on-screen instructions. You can choose the default installation path or specify a custom directory.

Step 3: Set Up Environment Variables

  1. Open the Start menu and search for Environment Variables.
  2. Click Edit the system environment variables.
  3. In the System Properties window, click Environment Variables.
  4. Under System variables, find the Path variable and click Edit.
  5. Add the path to the JDK’s bin directory (e.g., C:\Program Files\Java\jdk-21\bin).
  6. Click OK to save the changes.

Step 4: Verify the Installation

  1. Open Command Prompt and type: java -version
  2. If Java is installed correctly, you’ll see the version number displayed.

2. Installing Java on macOS

Step 1: Download the JDK

  1. Visit the official Oracle JDK website or the OpenJDK website.
  2. Download the macOS installer for the latest JDK version.

Step 2: Run the Installer

  1. Locate the downloaded .dmg file and double-click it to open the installer.
  2. Follow the on-screen instructions to complete the installation.

Step 3: Verify the Installation

  1. Open Terminal and type: java -version
  2. If Java is installed correctly, you’ll see the version number displayed.

3. Installing Java on Linux

Step 1: Update Your Package List

  1. Open Terminal and update your package list: sudo apt update

Step 2: Install OpenJDK

  1. Install the OpenJDK package: sudo apt install openjdk-21-jdk Replace 21 with the version number you want to install.

Step 3: Verify the Installation

  1. Check the Java version: java -version
  2. If Java is installed correctly, you’ll see the version number displayed.

Step 4: Set the Default Java Version (Optional)

If you have multiple Java versions installed, you can set the default version: