Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change java version (Mac)

I have 2 java versions on my computer:

/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

The 1.6.0 is set to default. How can I make my java programs to run 1.7?

Tried to add:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home

to my .zshrc file. But this seems to only change the path for my terminals java command.

Also tried to change the HOME symlink like this:

cd /Library/Java
mv Home Home-1.6
ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home/ Home

This had no effect at all.

Also tried java changer software: http://www.guigarage.com/2013/02/change-java-version-on-mac-os/ But no effect.

Any idea how to start java programs like .app and .jar files with the 1.7 version by just clicking on them?

like image 223
Grains Avatar asked Sep 27 '13 08:09

Grains


People also ask

How to change default Java version on Mac OS X?

This environment variable is where we tell the version of Java to be used as default. In the following steps, we will change the value of the default Java environment variable using the command line. Check all the installed Java versions on the local mac. First, we need to change the current directory to /usr/libexec using the cd command.

How do I change the Java version I have installed?

First, you need to make certain you have multiple JAVA versions installed. Note that there are two JDKs available. If you don’t notice the Java version you need to switch to, download and install the appropriate one from here (JDK 8 is represented as 1.8) . Once you have installed the appropriate JDK, repeat this step. 2.

How to set Java_home permanently in Mac?

To set JAVA_HOME permanently in Mac, I tried following steps. Download and install Java JDK to your Mac. When you install a Java JDK version which will be installed in the following location by default in MAC. Open the .bash_profile file (Here My Mac version is MacOS High Sierra. You may need to open .zshrc file in some different MacOS versions).

How to install multiple Java JDK versions on MacOS X?

Here is a quick tip on how to install multiple Java JDK versions (8, ..., 11, ..., 14 etc.) on macOS X and how to switch between them for your applications. Install multiple Java JDK versions using Homebrew. To install Homebrew run: Now install the Java JDK version 11 or above using brew cask:


3 Answers

I believe OS X (at least 10.8) uses the following paths:

  • JRE: /System/Library/Frameworks/JavaVM.framework/Versions/Current
  • JDK: /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK

Those are symlinks, which you can update to point to your 1.7 installation.

You can verify this fairly easily:

a) run which java to check which java executable is being executed. In theory, that should be /usr/bin/java.

b) run ls -la on your java executable, which should tell you where it points (/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java on my machine).

I think this should sort your .jar execution issue. If your Java application is wrapped in a .app, I believe it's a bit more complex: if memory serves, the version of java used will depend on the JavaApplicationStub being used by the .app.

like image 81
Nicolas Rinaudo Avatar answered Sep 18 '22 08:09

Nicolas Rinaudo


$ edit ~/.profile

#Java 1.8
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home
export PATH=${PATH}:${JAVA_HOME}


$ java -version

java version "1.8.0_20-ea"

here are the steps:

http://ukitech.blogspot.com/2014/04/switching-version-of-java-on-mac.html

like image 45
user3566154 Avatar answered Sep 19 '22 08:09

user3566154


You can always add into your profile both on Mac or Linux. Just create if doesn't exist ~/.profile file and there this line:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home

This should work .zshrc as well as .bash_profile are loaded only when terminal window is openned and profile when your graphical environment starts up.

like image 40
saganas Avatar answered Sep 19 '22 08:09

saganas