Java setup

Download Java

    • this is for Mac, you can find it for Windows/Linux on the same link.
    • https://www.oracle.com/in/java/technologies/downloads/#jdk20-mac
    • Download the JDK
      • Visit the official Oracle or OpenJDK website to download the desired version of the JDK compatible with ARM64 architecture (M1 chip).
    • Open Terminal:
      • You can find Terminal in the Utilities folder within your Applications folder. You can also use Spotlight search by pressing Command + Space and typing “Terminal”.
    • Check the Downloads Folder:
      • Downloaded files are usually saved to the “Downloads” folder by default. You might need to navigate to this folder using the terminal. You can use the cd (change directory) command to navigate.
    • Extract the Archive:
      • If the downloaded file is in a compressed format (e.g., .tar.gz), you’ll need to extract it using the tar command. Replace jdk-filename.tar.gz with the actual name of the downloaded file.
    • Move JDK to a Desired Location:
      • It’s recommended to move the extracted JDK to a location where it won’t be accidentally deleted. You can move it to the /Library/Java/JavaVirtualMachines/ directory, a common location for JDK installations.
    • Replace jdk-version with the actual name of the extracted directory.
    • Set JAVA_HOME:
      • You’ll need to set the JAVA_HOME environment variable to point to the JDK installation directory. Edit your shell profile configuration file (e.g., ~/.zshrc for the Zsh shell) using a text editor like nano or vim.
    • Add the following line to the file, replacing jdk-version with the actual version:

    •  

Some useful commands to check detailed Java installation.

  • Test Active Java
    • java -version
  • List installed JDKs
    • /usr/libexec/java_home -V
  • List Java Versions
    • /usr/libexec/java_home -V
  • Show system default i.e. highest version of Java
    • /usr/libexec/java_home
  • Execute system preferences
    • source ~/.bash_profile
  • Create .bash_profile if it does not exist
    • touch ~/.bash_profile
  • Open .bash_profile for editing
    • open -a TextEdit.app ~/.bash_profile
  • Switch active JDK
    • export JAVA_HOME=/usr/libexec/java_home -v <version>
  • To make it permanent on your system and the variable keeps working after closing the terminal, ou after a restart use:

    Add lines:

    Reopen the terminal and check if it worked:
Updated on Aug 08, 2023