mac replace java 6 with java 7 in /usr/bin/java - java

when I enter "whereis java" in terminal is says: /usr/bin/java
when I enter "java -version" it says "1.6.0_43" ...
when I open the Java control panel in system preference, the only version that i can see is Java 1.7.0_17 with the location at "/Library/Internet Plug-ins/JavaAppletPlugin.plugin/Contents/Home/bin/java". I don't have a "Java preference" panel that provides me to choose which version to use with some priority.
It is obvious that when internet browser is using, java 7 will be used and while I'm compiling Java in terminal Java 6 is used. But how could I get rid of Java 6? Is there a way that I could install Java 7 under /usr/bin/java?
BTW, I am not sure how to use the .profile file. Could i modify this file so that when I am in the terminal i can still use java 7?

Download Java SE 7u4 from Oracle.
Install it.
This version is different from the version downloaded while browsing the website.
It is really wired though...

In the meantime version 7u4 is no longer current and full of security holes!
My solution (which I got from the link provided in the comments) was to install the current Version of Java and start /Applications/Utilities/Java-Settings which displays the currently installed Java versions and allows to set the default version. Drag the current version to the top. Then /usr/bin/java pointed to the right version.

Related

Not able to switch the Java version to Java 17

Posting again since someone moved my question a community where there is not much activity and the solution provided there in the comment did not work.
I have installed Amazon Corretto Java 17 from here.
However, I am not able to switch the Java version to Java 17.
Following are the steps I have already tried:
1.
export JAVA_HOME=$(`/usr/libexec/java_home -v17`)
export JAVA_HOME=/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home
I have also check the highest version of Java using below command:
/usr/libexec/java_home and it shows correct Java 17 version:
/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home
I have also checked all the versions of Java installed on my machine using command /usr/libexec/java_home -V and it correctly shows Java 8, 11, and 17:
17.0.1 (x86_64) "Amazon.com Inc." - "Amazon Corretto 17" /Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home
11.0.9.1 (x86_64) "Amazon.com Inc." - "Amazon Corretto 11" /Users/harsh.pamnani/Library/Java/JavaVirtualMachines/corretto-11.0.9.1/Contents/Home
1.8.0_275 (x86_64) "Amazon" - "Amazon Corretto 8" /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home
I also added JAVA_HOME exports mentioned in step-1 and step-2 to .zshrc and .bash_profile as well.
I have followed multiple questions on StackOverflow and multiple
blogs as well. For example,
How to set or change the default Java (JDK) version on macOS?
switch java version on mac OS
https://java.tutorials24x7.com/blog/how-to-switch-java-version-on-mac
https://www.lotharschulz.info/2019/08/21/mac-change-default-java-version
https://akrabat.com/using-jenv-to-select-java-version-on-macos/
https://www.happycoders.eu/java/how-to-switch-multiple-java-versions-windows/
I am using jenv to switch between different java versions. Even jenv is not able to find Java 17. I used jenv versions and following is the output:
system
1.8
1.8.0.275
11
11.0
* 11.0.9.1 (set by /Users/harsh.pamnani/.jenv/version)
corretto64-1.8.0.275
corretto64-11.0.9.1
I have also checked that JAVA_HOME is pointing to Java 17. Here is the screenshot: Screenshot
Even after following all the steps above when I do java --version, it is still set to Java 11:
openjdk 11.0.9.1 2020-11-04 LTS
OpenJDK Runtime Environment Corretto-11.0.9.12.1 (build 11.0.9.1+12-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.9.12.1 (build 11.0.9.1+12-LTS, mixed mode)
I have also checked PATH variable, and nothing seems to be relatable to Java. Following is the output for path variables:
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Users/harsh.pamnani/Downloads/apache-maven-3.6.3/bin
Could someone please help me understand if I am missing anything here. Thank you.
which java is often used to find the exact executable you are calling when you type in java.
Keep in mind that when you type in the command java your JAVA_HOME setting is not used. Rather, the operating system PATH setting is used. If you have an older copy of java "before" the one you want to use on the path, then that's what the operating system will give you. To fix a problem like this, you need to alter your path such that the directory of your desired java version comes before any other java versions.
I do see that you checked your PATH setting, but I think you didn't know what to check, because you only listed directories. In those directories, a java executable exists. If the old executable comes in a directory earlier in the path, that's the version of java you will get when running it from the command line, regardless of any other settings.
Now, it is still important to have the JAVA_HOME set correctly, because when various Java tools want to discover items, thy might read JAVA_HOME (and if it is wrong, get directed to a non-matching JVM).

how do i fix error in java version coding "java_home: option requires an argument -- v"?

Recently I downloaded Java SE 8 as Java SE 14 was causing me some issues on my mac. I had downloaded it and tried to change the coding in terminal to change my version of java from 14 to 8 by following along to a website, and when I had completed I double-checked to see if the coding had worked by typing
java -version and it stated I was still on 14. So I attempted redoing the whole coding process over again but when I typed /usr/libexec/java_home -v instead of telling me what java options are available, instead it states "java_home: option requires an argument -- v"
pls anyone help.
You're getting that message because you have to indicate a Java version number when you use the -v flag.
On MacOS, to find all versions of Java installed on your machine, type:
/usr/libexec/java_home -V
Note capitalization. This argument will show you the path of all JVMs installed on your Mac.
For the lowercase flag, you can see the install path of specific versions of Java. For example:
/usr/libexec/java_home -v 1.8
will show you all versions of Java 1.8 installed. You got the error message because you were indeed missing an argument: the Java version number.

How many java versions do i have installed on my Mac?

I'm a bit confused now. When I run the command java --version in the terminal i get: java 13.0.1. When I open the system preferences and click the java app and then about, i see it says Java version 8 1.8.0_231
Does that mean I have 8, 13 or both?
When I check through the java app.
When I check through the terminal.
When i check for all JDK installed on my system (only 1 version pop ups).
You can have multiple JDK installed in one machine but you can have only one version set as default Java SDK. Looks like you have Java 13 set as default.
Try running the following :
echo $JAVA_HOME
You can also go to the tab Java and see the list of all Java Runtime Environments (JRE.)
Please note that just because you have multiple JREs available doesnot mean all corresponding SDK are also there.
You can have many version of java on your Mac. But you can run only one of this in a process.
On my Mac, system preferences run with java path :
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
But in terminal, this run with java path:
/usr/bin/java
I think you can replace java file in /usr/bin by another version java you want.
that means you jdk version is 13 , and your jre version is 1.8.
jre is used for running java apps ,and the jdk(java development kit) is for building apps with java language. java jdk is like the android sdk

Java 11 does not set Java Environment Variable

usually when installing an updated JRE, the environment variables will be set so that running any java command in CMD will use the new version.
I've just installed JDK 11 which doesn't have a JRE equivalent - well it's in the JDK - but java commands are still being sent to JRE 8.
This is no problem for me, I can always change the environment vars myself and point to "C:\Program Files/java/jdk-11/bin/java.exe", but anyone who wants to use my program, which requires Java 11, will not have their variables set and it's a bit much to ask them to do so.
Why are they not being set on a standard Java 11 install? Am I being stupid?
Oracle is still pushing 8 as the "end user" Java install. That's why it's the only one you can find on java.com. Newer versions of Java are designed either for back-end use on servers, or to be bundled with the application itself. The latter option is what you want.

Understanding Oracle's Java on Mac

I've been using Java on OS X for many, many years and recently when Apple stopped including Java by default I let the OS go and install it for me (Apple's variety, of course).
So now I'm using OS X 10.8 and I need to install Java 7 so I just got Oracle's Update 15 in DMG form and ran the installer. It updated my /usr/bin/java (and related files) to point here:
/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
Tracing this back to '/System/Library/Frameworks/JavaVM.framework/Versions' everything either points to 'Current' or 'CurrentJDK', the former being a link to 'A' (which is Oracle's Java 7, from what I can tell, not sure why it is 'A') and the latter being a link to Apple's Java 6 in '/System/Library/Java/JavaVirtualMachines/1.6.0.jdk'.
Now this is all really confusing but this isn't even my question yet. It appears there is a Java 7 installed here:
/System/Library/Frameworks/JavaVM.framework/Versions/A
But there is also a Java 7 installed here:
/Library/Java/JavaVirtualMachines/jdk1.7.0_15.jdk
Finding 'java' in both and printing out the version yields the same version and build (java version "1.7.0_15"), however, when hashing the files they are different.
So does this mean Oracle installed Java 7 in two different places? If so, why? Which am I supposed to use? And why do some things still point to Java 6 (CurrentJDK).
I've looked on Oracle's website but nothing there clears anything up.
Oracle's JVM is only installed in one location. You've been misled!
As you've noted, the Java commands in /usr/bin are symlinks to binaries in /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands. The binaries within that directory are stub applications that determine which Java VM to use*, and then exec the corresponding real binary within that VM version. This is why all of the binaries within /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands are almost identical in size, despite the fact that you'd expect them to be implementing quite different functionality.
You can see this in action by using dtrace:
mrowe#angara:~$ sudo dtrace -n 'syscall::posix_spawn:entry { trace(copyinstr(arg1)); }' -c "/usr/bin/java -version"
dtrace: description 'syscall::posix_spawn:entry ' matched 1 probe
dtrace: pid 44727 has exited
CPU ID FUNCTION:NAME
8 619 posix_spawn:entry /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java
The given dtrace invocation prints out the path argument to posix_spawn when it is called by java -version. In my case the stub application has found Apple's Java 1.6 runtime in /System/Library/Java/JavaVirtualMachines/1.6.0.jdk and is invoking that version of the java command.
The stub binaries also have another benefit: when they detect that no Java VM is installed they will prompt the user to install one.
As for the CurrentJDK symlink, as best as I can tell this for sake of backwards-compatibility with the past when Apple was the only source of the JVM on OS X.
* A combination of factors are considered when determining which Java VM should be used. JAVA_HOME is used if set (try JAVA_HOME=/tmp java). If JAVA_HOME is not set then the list of all virtual machines on the system is discovered. The JAVA_VERSION and JAVA_ARCH environment variables are used, if set, to filter the list of virtual machines to a particular version and supported architecture. The resulting list is then sorted by architecture (preferring 64-bit over 32-bit) and version (newer is better), and the best match is returned.
The Oracle Java 7 JRE (i.e. the one that is used by the web browser plugin to run applets and Java Web Start) installs itself in /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home, and it is this one that any automatic updates will affect. The JDK (the one you download from http://www.oracle.com/technetwork/java/javase/downloads/index.html) installs by creating a directory under /Library/Java/JavaVirtualMachines, and it's up to you to update this yourself. You can have multiple JDK versions installed side by side but only one "public" JRE under JavaAppletPlugin.plugin (which will correspond to the latest installed JDK or a later version if it has been auto-updated since).
As explained by bdash, the commands under /usr/bin are stubs that delegate to whichever JDK/JRE is pointed to by the JAVA_HOME environment variable, or if that is not set then they will pick the most appropriate Java to run. You can use /usr/libexec/java_home to see which one the stubs would pick. If no Java is installed the stubs will offer to install the latest Apple Java 6 (as far as I know they will not offer to install Java 7).
I find this post:
https://developer.apple.com/library/mac/qa/qa1170/_index.html
The /usr/libexec/java_home tool dynamically finds the top Java version specified in Java Preferences for the current user.

Categories

Resources