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)
- Visit the official Oracle JDK website or the OpenJDK website.
- Choose the latest version of the JDK (e.g., Java 21) and download the installer for Windows.
Step 2: Run the Installer
- Locate the downloaded
.exe
file and double-click it to start the installation. - Follow the on-screen instructions. You can choose the default installation path or specify a custom directory.
Step 3: Set Up Environment Variables
- Open the Start menu and search for Environment Variables.
- Click Edit the system environment variables.
- In the System Properties window, click Environment Variables.
- Under System variables, find the
Path
variable and click Edit. - Add the path to the JDK’s
bin
directory (e.g.,C:\Program Files\Java\jdk-21\bin
). - Click OK to save the changes.
Step 4: Verify the Installation
- Open Command Prompt and type:
java -version
- If Java is installed correctly, you’ll see the version number displayed.
2. Installing Java on macOS
Step 1: Download the JDK
- Visit the official Oracle JDK website or the OpenJDK website.
- Download the macOS installer for the latest JDK version.
Step 2: Run the Installer
- Locate the downloaded
.dmg
file and double-click it to open the installer. - Follow the on-screen instructions to complete the installation.
Step 3: Verify the Installation
- Open Terminal and type:
java -version
- If Java is installed correctly, you’ll see the version number displayed.
3. Installing Java on Linux
Step 1: Update Your Package List
- Open Terminal and update your package list:
sudo apt update
Step 2: Install OpenJDK
- Install the OpenJDK package:
sudo apt install openjdk-21-jdk
Replace21
with the version number you want to install.
Step 3: Verify the Installation
- Check the Java version:
java -version
- 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: