Logo

dev-resources.site

for different kinds of informations.

Change the default Java Version on macOS

Published at
2/19/2022
Categories
macos
java
jdk
javase8
Author
rithvik78
Categories
4 categories in total
macos
open
java
open
jdk
open
javase8
open
Author
9 person written this
rithvik78
open
Change the default Java Version on macOS

Here, We are trying to change the version to Java SE 8

First run /usr/libexec/java_home -V which will output something like the following:

Matching Java Virtual Machines (3):
    16.0.2 (x86_64) "Oracle Corporation" - "Java SE 16.0.2" /Library/Java/JavaVirtualMachines/jdk-16.0.2.jdk/Contents/Home
    1.8.202.08 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_202 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk-16.0.2.jdk/Contents/Home
Enter fullscreen mode Exit fullscreen mode

Pick the version you want to be the default (1.8.0_202) then:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_202`
Enter fullscreen mode Exit fullscreen mode

Now when you run java -version you will see:

java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)
Enter fullscreen mode Exit fullscreen mode

Add the

export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_202`
Enter fullscreen mode Exit fullscreen mode

line to your shell’s init file.

Updating the .zshrc file should work:

nano ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

paste the line

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0_202)
Enter fullscreen mode Exit fullscreen mode

at bottom of the file.

Press CTRL+X to exit the editor, Press Y to save your changes.

source ~/.zshrc
echo $JAVA_HOME
java -version
Enter fullscreen mode Exit fullscreen mode

Output should be:

java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)
Enter fullscreen mode Exit fullscreen mode

Resources

Stackoverflow

jdk Article's
30 articles in total
Favicon
Garbage Collection in Java: Progress Since JDK 8
Favicon
Day 5 - sudo,apt,jdk
Favicon
1.What is APT in Linux?2.what is JDK in Linux?3.what happened behind the screen, after we entering JavaC?
Favicon
Preparando o ambiente de desenvolvimento da melhor API de tabelas de campeonato que você já viu!
Favicon
Java Compilation Process : From Source Code to Bytecode Execution
Favicon
Java JVM, JRE and JDK
Favicon
Exploring the New Features of Java 23
Favicon
# Must-Know Features in JDK 23: What’s New for Java Developers? 🚀
Favicon
Enhancing Performance with Static Analysis, Image Initialization and Heap Snapshotting
Favicon
JDK Setup On Linux, Windows, Mac
Favicon
Memory Management in GraalVM Native Image
Favicon
Fundamental Questions of Java
Favicon
Tổng quan về công nghệ java
Favicon
El Anuncio de Microsoft: Microsoft Build for OpenJDK 21
Favicon
Using JDK21 Preview Features and/or incubator classes
Favicon
How to Install Java JDK 17 on Windows 10
Favicon
VSCode Java Extension Pack Auto Config
Favicon
How to install Java in Pop!_Os
Favicon
Getting Started with Java Programming: Downloading and Installing JDK and IntelliJ
Favicon
Como intalar o Java JDK 17 no Ubuntu 22.04
Favicon
Instalando o JDK 17 ou 21 no Windows 11
Favicon
Spring boot 2.7.7 application deployment on Glassfish 6.2.3
Favicon
Step-by-Step Guide to Migrating from Java 8 to Java 17 (or Later): Tips, Checklist and Best Practices
Favicon
Switching between multiple versions of various tools
Favicon
Encryption raised an exception
Favicon
Install Java JDK on Arch Linux
Favicon
JDK vs JRE vs JVM: Asosiy Farqlari
Favicon
JVM, JDK,JRE ve ClassLoader Nedir ?
Favicon
Change the default Java Version on macOS
Favicon
The state of pattern matching in Java 17

Featured ones: