Keeping your Java installation up to date is essential for maintaining robust security, accessing new language features, and ensuring optimal performance for your applications. Outdated versions can become vulnerable to exploits and may not be compatible with the latest frameworks or development tools. This guide provides a clear, step-by-step walkthrough for updating Java across various operating systems, helping you manage your runtime environment effectively.

Before initiating the update process, it is crucial to understand the distinction between Java Runtime Environment (JRE) and Java Development Kit (JDK). The JRE is required to run Java applications, while the JDK is necessary for developers who need to compile and debug code. Depending on your specific needs, you might be updating one or both components. Knowing which version you currently have installed allows you to select the correct download and avoid potential conflicts.

Checking Your Current Java Version
To determine if an update is necessary, you should first verify your current installation. This diagnostic step ensures you are proceeding with the right version and provides a baseline for the update. The process is straightforward and identical across Windows, macOS, and Linux distributions.

Using the Command Line
Open your terminal or command prompt and execute the following command. This action queries the Java executable in your system's PATH and returns the version number immediately.

java -version |
The output will display the version number, such as "java version "21.0.1"". If you receive an error indicating the command was not found, Java is either not installed or the executable path is not configured correctly in your environment variables.
Downloading the Latest Release

Once you have identified your current version, the next step is to acquire the latest build. Oracle maintains the official distribution, but several vendors offer builds with different licensing terms. For most users, the official Oracle JDK or the Eclipse Adoptium builds are the safest choices. Always ensure you download the correct architecture—either x64 or ARM—for your operating system.
- Visit the official Oracle Java Downloads Page or the Eclipse Adoptium archive.
- Select the appropriate version for your operating system (Windows, macOS, Linux).
- Choose the correct file type, such as MSI for Windows, PKG for macOS, or TAR/GZ for Linux.
Installing the Update on Windows

Windows users benefit from a guided installation process that handles configuration automatically. After downloading the installer, running it will update your existing installation without disrupting your environment variables.
Step-by-Step Installation




















Double-click the downloaded .MSI file and follow the prompts in the setup wizard. The installer will typically remove the previous version and install the new one in the same directory, ensuring a clean transition. Once the progress bar completes, you should restart your command prompt to refresh the Java link to the new files.
Updating on macOS and Linux
Mac and Linux systems provide flexibility in how Java is managed. While you can run the PKG or TAR installer, using a package manager is often recommended for easier maintenance and rollback capabilities. Tools like Homebrew on macOS or Apt/Yum on Linux handle dependencies and path configuration seamlessly.
Using Package Managers
For macOS users with Homebrew, the command brew upgrade openjdk efficiently fetches and installs the latest version. On Linux, distributions using Apt can utilize sudo apt update && sudo apt install openjdk-21-jdk to manage the update. These methods ensure that the system's package index is current before applying the upgrade.
Verifying the Update
After the installation is complete, it is vital to confirm that the update was successful and that the system is using the correct version. This verification step closes the loop in the update cycle and ensures your environment is ready for development or runtime.
Repeat the initial diagnostic command to check the version.
java -version |
The output should now reflect the new major version number you installed. If the version number does not change, you may need to adjust your system's PATH variable to point to the new installation directory, particularly on Linux where multiple versions might exist.
Managing Environment Variables
For developers working with multiple Java versions, managing the PATH and JAVA_HOME variables becomes critical. Incorrect settings can cause scripts or IDEs to reference an outdated Java executable, leading to confusing build errors. Proper configuration ensures that your tooling chain targets the correct runtime.
On Windows, you can set JAVA_HOME via System Properties > Advanced > Environment Variables. On Unix-based systems, export the variable in your shell profile file (.bashrc, .zshrc). Setting JAVA_HOME to the root directory of your JDK (e.g., /Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home) provides stability for compilers and servers that rely on it.