DEV Community

Khairun Nahar Nowrin
Khairun Nahar Nowrin

Posted on

Install Java in macOs (M1)

  1. First run the command
java -version
Enter fullscreen mode Exit fullscreen mode

for check the java version. If Java is not available in your local machine then it will return the below message.
Image description.

  1. Go to - https://www.oracle.com/java/technologies/downloads/#jdk17-mac. and download Arm 64 DMG Installer. Select your desire java version. as i select JAVA 17. then install "Arm 64 DMG Installer" for Mac (m1) and for other intel version install "x64 DMG Installer"

Image description
Install it and again run command

Image description

Java successfully install your local machine. After that run

echo $JAVA_HOME
Enter fullscreen mode Exit fullscreen mode
/usr/libexec/java_home
Enter fullscreen mode Exit fullscreen mode
touch ~/.zshrc
Enter fullscreen mode Exit fullscreen mode
open ~/.zshenv
Enter fullscreen mode Exit fullscreen mode

and write export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.0.5.jdk/Contents/Home
after that run cat command for reads data from the file and gives their content as output

cat ~/.zshrc
Enter fullscreen mode Exit fullscreen mode
echo $JAVA_HOME   
Enter fullscreen mode Exit fullscreen mode

Java home yet not save to save it Run

source ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

Run source command for reads and executes the file content in the current shell.
Again run

 echo $JAVA_HOME
Enter fullscreen mode Exit fullscreen mode

It return JAVA_HOME path.

Top comments (1)

Collapse
 
khairunnaharnowrin profile image
Khairun Nahar Nowrin