The Java Development Kit (JDK) is a software development environment that works across different platforms. It provides tools and libraries required for creating Java programs. This article will give detailed instructions on installing the JDK on Windows and macOS operating systems.
Table of contents
Install JDK on Windows
Download and Install JDK
Go to the official Oracle website to download the Java Development Kit (JDK).
Choose the appropriate Java version and select the Windows tab based on your system preference. Then, click on the available URL options (i.e., .zip, .exe, or .msi file) on the bottom side of the page to start the download.
Notice that we have not chosen the latest version of Java in the above example based on personal preference. However, you can select newer JDK versions to explore new features.
After completing the download, follow the provided instructions to install the JDK.
Configure environment variables
The next thing is to set up the environmental variables to achieve proper system configuration and dependency for the other applications.
Open System Properties by pressing Win + R, typing sysdm.cpl, and click OK.
Click the Advanced system settings tab and click the Environment Variables button.
Under System variables, click on the New button to create a new variable named JAVA_HOME. Set its value to your Java JDK installation path, such as C:\Program Files\Java\jdk-17.
Then, select the Path variable option in the System variables and click Edit.
Add a new entry by clicking the New button, and in the new row, put the path to the Java folder followed by \bin. Then, click the OK buttons to save the changes.
Check the Java version
After setting the variables, open a new command prompt and type java -version to verify the installation. The prompt should show the installed version number.
Install JDK on macOS
Download and install JDK
Go to the official Oracle website to download the Java Development Kit (JDK).
Select the macOS tab and the Java version you want to download. We’ll download the latest ARMx64 DMG Installer for our Mac for JDK 17.
Notice that we have not chosen the latest version of Java in the above example based on personal preference. However, you can select newer JDK versions to explore new features.
After the download, install the JDK by following the guided installation steps.
Configure environment variables
Now, we need to configure some Java environment variables. Start by opening a terminal and passing the following command to find out the version of Java that is installed and its location in our computer:
You can open a terminal by pressing Command + Space to open Spotlight Search, then type “Terminal” and press Enter. This will launch the Terminal application.
/usr/libexec/java_home -V
The next step is to set JAVA_HOME in the .zshrc file. To check if you already have that file, run this command from your home directory in the Terminal:
ls -al
Run the following command in the Terminal if you don’t see a .zshrc file:
touch .zshrcCode language: CSS (css)
Now, let’s open the file:
nano .zshrcCode language: CSS (css)
And add these lines to it and make sure that you replace <your_java_version> with the version of Java that you have installed:
export JAVA_HOME=$(/usr/libexec/java_home -v <your_java_version>)
export PATH=$JAVA_HOME/bin:$PATHCode language: JavaScript (javascript)
After that, we have to save the changes in the nano editor. Press control + X, then press Y to confirm you want to save and finally, press Enter to confirm the changes.
Now, run this command:
source .zshrcCode language: CSS (css)
This command will reload your shell configuration and apply the changes immediately without restarting your terminal.
You can now verify the JAVA_HOME variable and Java version by running the following commands one after the other:
echo $JAVA_HOME
java -versionCode language: PHP (php)
Additional configuration
Before the JDK download and installation, you should check if you already have an old version of Java, as it could interfere with your new JDK installation.
To check for existing Java installations, use this command in your terminal:
/usr/libexec/java_home -V
This command will display all the Java versions of JDK or JRE installed on your system.
You should remove any existing JDK or JRE Java version unless you intend to use multiple Java versions.
For manually installed versions, delete the corresponding folders in /Library/Java/JavaVirtualMachines/.
For versions installed through the macOS installer, use the official Java uninstaller tool from Oracle.
Removing the older or incompatible Java installations assures that your system uses the newly installed JDK version without interference. This prevents potential conflicts that could hamper the proper functioning of your Java development environment.
Final thoughts on how to install Java JDK on Windows and macOS
The Java JDK is used by Java developers to develop Java applications. Its installation on Windows and macOS is straightforward. You download the appropriate installer from the Oracle JDK website, run it, and configure system environment variables and PATH. Java JDK is necessary for developers and testers because it provides essential tools, compilers, and runtime environments for efficient Java programming.
Following these steps, you can quickly set up your Java development environment, including class libraries and JVM. Remember to verify your installation by checking the Java version in the command prompt or terminal. With Java JDK properly installed, you’ll be ready to start your Java programming for various projects, from simple applications to complex Maven builds, taking advantage of its strong features and cross-platform compatibility. Happy testing!
Don’t miss these
Follow our blog
Be the first to know when we publish new content.
- How to find an element in Selenium - October 5, 2024
- Resolved: SessionNotCreatedException - October 2, 2024
- Katalon Recorder Automation Overview - September 12, 2024
Keep in mind this installs a version from Oracle that requires a license for commercial use. You can also get an open source version from Amazon that does not require the licensing for commercial use.
Excellent point, Nick. Thanks for the tip!