How to install Java 21 and setup JAVA_HOME Path in macOS đ (Apple Silicon M1 & M2)
If youâre a proud owner of an Apple Silicon M1 or M2 Mac, you may be wondering how to install Java and set up the JAVA_HOME path. Java is a versatile programming language thatâs used in various applications, and having it properly installed on your macOS is essential for developers and tech enthusiasts. In this guide, weâll walk you through the steps to get Java up and running on your Apple Silicon Mac.
Step 1: Download the Appropriate Java Version â
Apple Silicon Macs use a different architecture compared to their Intel-based predecessors. Therefore, you need to download a Java version thatâs compatible with Apple Silicon.
- Open your web browser and open the Java Downloads section on Oracle website.
- Select the âLatest Java Releaseâ for macOS.
- Click the ARM64 DMG Installer download link to save the file to your computer.
Step 2: Install Java đ ď¸
Now that youâve downloaded the appropriate Java version, itâs time to install it on your Mac:
- Locate the downloaded file (usually in your âDownloadsâ folder) and double-click it to open the installation package.
- Follow the on-screen instructions to complete the installation process. This will involve accepting the license agreement.
Step 3: Verify Your Java Installation âď¸
To ensure that Java is correctly installed open your Terminal and type:
java --version
You should see Java version displayed on the screen.
Step 4: Set Up JAVA_HOME đ
To make Java easily accessible for development purposes, youâll have to set up the JAVA_HOME environment variable. Please follow the following steps to setup JAVA_HOME path in your macOS.
- Open the Terminal application (you can find it in the âUtilitiesâ folder within the âApplicationsâ folder).
- Create the zShell Environment file if you donât have it. The Environment file should be stored at the root directory of your mac and itâs name should be â.zshenvâ. Use the below code to create your zShell Environment file.
touch ~/.zshenv
- Use the following code to open the zShell Environment file.
open ~/.zshenv
- Add the below path in your zShell Environment file and save it.
export JAVA_HOME=$(/usr/libexec/java_home)
- Enter the following code in the terminal after you saved and closed the environment file to apply the changes and refresh your profile.
source ~/.zshenv
Your JAVA_HOME path is set successfully in the zShell Environment file. Cheersđť
Step 5: Verify Your JAVA_HOME Setup âď¸
To ensure that Java is correctly installed and the JAVA_HOME path is set up, open your Terminal and type:
echo $JAVA_HOME
Conclusion đ
Congratulations! Youâve successfully installed Java and set up the JAVA_HOME path on your Apple Silicon M1 or M2 Mac. Youâre now ready to start coding and developing Java applications with ease.
Remember to keep your Java installation up-to-date and explore the exciting world of Java development on your powerful Apple Silicon Mac! đťđâ¨
If you have any questions or run into any issues during the installation process, feel free to reach out to the Java community or consult the official documentation for further assistance. Happy coding! đđ¨âđťđŠâđť