Link to home
Start Free TrialLog in
Avatar of Guddi Yadav
Guddi YadavFlag for United States of America

asked on

How to change Java version on Mac OS Bigsur ?

I am having trouble to change Java version from 1,8 to 1.11. Need help. Thanks
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Think you would need to explain what 'having trouble' means, we can't guess what is wrong?
You probably should just consider changing the value of variable JAVA_HOME, prior to running java
Avatar of Guddi Yadav

ASKER

I ran
unset JAVA_HOME
export JAVA_HOME=$(/usr/libexec/java_home -v "11.0.6”)

when I do java -version
It is still showing 1.8
/usr/libexec/java_home -v "11.0.6”

Open in new window

What happens when you just do that in Terminal?
I would put the following in ~/.bashrc

export JAVA_HOME=whatever
export PATH=$JAVA_HOME/bin:$PATH

Open in new window

I get below

Matching Java Virtual Machines (4):
    12 (x86_64) "Oracle Corporation" - "OpenJDK 12" /Library/Java/JavaVirtualMachines/jdk-12.jdk/Contents/Home
    11.0.6 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 11" /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
    10.0.1 (x86_64) "Oracle Corporation" - "Java SE 10.0.1" /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
    1.8.0_181 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-12.jdk/Contents/Home

I am using .zsh

I get below
Yes, that's not going to be helpful in your assignment to a variable ;)
Try what I posted. You'll need to source ~/.bashrc for it to take effect
.zshrc in that case
I tried in bash, it works but if I close terminal it again shows old Java 1.8 Basically it changes temporarily
How can make it final 
If your shell is zsh then you need to do that in .zshrc - did you?
To add to the good suggestions by CEHJ: what do you have in your ~/.zprofile file?
That is likely where your JAVA_HOME would be defined as well as where it is added to the PATH - that is where you could update.
You could also check /etc/zprofile (or /etc/profile) where path_helper is helping to construct PATH
You could also check /etc/zprofile (or /etc/profile) where path_helper is helping to construct PATH
Is that right? The reason I ask is that on Linux, it's actually
/etc/zsh/zprofile

Also, on Linux

$ZDOTDIR/.zprofile
$ZDOTDIR/.zshrc

$ZDOTDIR often is $HOME, but not necessarily so
@CEHJ - I verified this on a Mac - so yes what I wrote is correct.

@Guddi - can you post details about you config files?
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.