Installation Guide - ashwani-cse/next-gen-pizza-backend GitHub Wiki
Installing and Switching Between JDK 17, JDK 21, and JDK 24 on macOS
Step 1: Check Installed JDK Versions
To list all installed JDK versions and their paths, run:
/usr/libexec/java_home -V
Expected output:
Matching Java Virtual Machines (4):
24 (x86_64) "Oracle Corporation" - "OpenJDK 24" /Users/ashwanikumar/Library/Java/JavaVirtualMachines/jdk-24.jdk/Contents/Home
21.0.6 (arm64) "Oracle Corporation" - "Java SE 21.0.6" /Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home
17.0.10 (arm64) "Oracle Corporation" - "Java SE 17.0.10" /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
17.0.10 (arm64) "Eclipse Adoptium" - "OpenJDK 17.0.10" /Users/ashwanikumar/Library/Java/JavaVirtualMachines/temurin-17.0.10/Contents/Home
This command is useful as some users extract JDK manually into /Users/
instead of /Library/Java/JavaVirtualMachines/
.
Download JDK 24](https://jdk.java.net/)
Step 2: [Go to the official OpenJDK website:
🔗 [[Download JDK 24](https://jdk.java.net/)](https://jdk.java.net/)
Download the macOS x64 tar.gz file. It will be saved in the Downloads
folder by default.
Step 3: Extract JDK 24
Move the downloaded JDK 24 tarball to a proper location and extract it.
mkdir -p ~/Library/Java/JavaVirtualMachines/jdk-24
mv ~/Downloads/openjdk-24_macos-x64_bin.tar.gz ~/Library/Java/JavaVirtualMachines/jdk-24/
cd ~/Library/Java/JavaVirtualMachines/jdk-24
tar -xzf openjdk-24_macos-x64_bin.tar.gz --strip-components=1
Verify Extraction
Check if the extracted folder exists:
ls ~/Library/Java/JavaVirtualMachines/
Expected output:
temurin-17.0.10
jdk-24
Find the extracted JDK 24 path:
ls ~/Library/Java/JavaVirtualMachines/jdk-24/
It should contain Contents/Home
, so the JDK 24 path is:
/Users/ashwanikumar/Library/Java/JavaVirtualMachines/jdk-24/Contents/Home
Step 4: Set JDK 24 as Default
Ensure .zshrc
exists before modifying it.
[ -f ~/.zshrc ] || touch ~/.zshrc
nano ~/.zshrc
Add the following lines:
export JAVA_HOME=$(/usr/libexec/java_home -v 24)
export PATH=$JAVA_HOME/bin:$PATH
Save and exit (Ctrl + X → Y → Enter).
Apply changes:
source ~/.zshrc
Verify:
java -version
Expected output:
openjdk 24 ...
Step 5: Easily Switch Between JDK 17, JDK 21 & JDK 24
Instead of editing .zshrc
every time, add alias commands for switching.
nano ~/.zshrc
Add these lines at the end:
alias set_java17='export JAVA_HOME=$(/usr/libexec/java_home -v 17); export PATH=$JAVA_HOME/bin:$PATH; echo "Switched to Java 17: $JAVA_HOME"'
alias set_java21='export JAVA_HOME=$(/usr/libexec/java_home -v 21); export PATH=$JAVA_HOME/bin:$PATH; echo "Switched to Java 21: $JAVA_HOME"'
alias set_java24='export JAVA_HOME=$(/usr/libexec/java_home -v 24); export PATH=$JAVA_HOME/bin:$PATH; echo "Switched to Java 24: $JAVA_HOME"'
Save and exit (Ctrl + X → Y → Enter).
Apply changes:
source ~/.zshrc
Step 6: Switching Between JDK Versions
- Switch to JDK 17:
set_java17
- Switch to JDK 21:
set_java21
- Switch to JDK 24:
set_java24
Verify the version:
java -version
✅ Final Setup Summary
✔ JDK 24 downloaded from [[[jdk.java.net](https://jdk.java.net/)](https://jdk.java.net/)
✔ JDK 24 installed from tar.gz
✔ JDK 24 set as default
✔ One-command switch between JDK 17, JDK 21 & JDK 24 using java_home
This .md
file is GitHub Wiki ready and fully copy-paste friendly. Let me know if you need any modifications! 🚀