How to downgrade Java on El Capitan - java

How do you downgrade Java version on MacOSX El Capitan? Right now when I run java -version I get:
java version "9.0.1" Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
I need to have it say:
java version "1.8.0_25" Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
So I can run a specific npm java based package.
I tried following instructions on Java website for uninstall/re-install with no luck. They suggest to run these 3 commands:
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -fr ~/Library/Application\ Support/Java
Doing this seems to do nothing. When I run java -version I still get the same result.
I watched this video But I cannot find the JavaAppletPlugin.plugin referenced in video.
What am I doing wrong? How do you change Java version on El Capitan Mac OS?

Look at SDKMAN - http://sdkman.io/
You install it, then do sdk list java
sdk list java
================================================================================
Available Java Versions
================================================================================
9.0.1-zulu
9.0.1-oracle
9.0.0-zulu
8u152-zulu
8u151-oracle
8u144-zulu
> + 8u141-oracle
8u131-zulu
7u141-zulu
6u65-apple
You can install any or all of these, and select whichever one you want to use and set a default, as well:
See the docs here:
http://sdkman.io/usage.html

Related

Unable to create Z shell alias to "activate" Java 8 (OpenJDK) on macOS

Summary
I have followed the advice given in this answer to create aliases which allow me to quickly switch between JVM versions on macOS. And I have cross-checked with this article, which suggests a similar solution. This works well for Java 15, but not for Java 8. See details below.
Details
Details of macOS version:
$ sw_vers
ProductName: macOS
ProductVersion: 12.1
BuildVersion: 21C52
Details of installed Java versions:
$ java --version
java version "15.0.1" 2020-10-20
Java(TM) SE Runtime Environment (build 15.0.1+9-18)
Java HotSpot(TM) 64-Bit Server VM (build 15.0.1+9-18, mixed mode, sharing)
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
15.0.1 (x86_64) "Oracle Corporation" - "Java SE 15.0.1" /Library/Java/JavaVirtualMachines/jdk-15.0.1.jdk/Contents/Home
1.8.301.09 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_292 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-15.0.1.jdk/Contents/Home
And this is from my .zshrc:
# Aliases to quickly change active JVM version
export JAVA_8_HOME=$(/usr/libexec/java_home -v 1.8)
export JAVA_15_HOME=$(/usr/libexec/java_home -v 15)
alias java8="export JAVA_HOME=$JAVA_8_HOME"
alias java15="export JAVA_HOME=$JAVA_15_HOME"
# Set default to Java 15
java15
When I source the .zshrc file, there are no errors.
However, when I run the alias java8, I get the following error:
$ java8
export: not valid in this context: Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
And the active Java version has not changed, i.e., it is still 15.0.1 (my default).
At first, I suspected the version number in my alias was wrong. I have tried changing the name in my .zshrc to the fully qualified name (1.8.0_292):
export JAVA_8_HOME=$(/usr/libexec/java_home -v 1.8.0_292)
alias java8="export JAVA_HOME=$JAVA_8_HOME"
When I run the alias java8 again, after sourcing the updated .zshrc, I no longer get an error. But now my Java environment is in a broken state:
$ java --version
Unrecognized option: --version
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
$JAVA_HOME updates, though, so at least the alias works now:
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
Fortunately, I can use my other alias, java15, to get my environment back in a working state:
$ java15
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-15.0.1.jdk/Contents/Home
$ java --version
java 15.0.1 2020-10-20
Java(TM) SE Runtime Environment (build 15.0.1+9-18)
Java HotSpot(TM) 64-Bit Server VM (build 15.0.1+9-18, mixed mode, sharing)
This indicates that the aliases are indeed working, at least java15. But, for some reason, java8 "refuses" to "activate," no matter what version number I put in my alias.
Note that I have installed the OpenJDK version for Java 8, because Oracle's versions are no longer available on their website, nor via Homebrew.
This is exactly how I installed Java 8 on my system, just in case it's relevant:
$ brew tap adoptopenjdk/openjdk
$ brew install adoptopenjdk8
Lastly, I am able to use Java 8 by "manually" specifying it for specific commands, e.g., when using Clojure/Leiningen. For example, this works fine:
$ JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home lein repl
This suggests that the Java 8 installation is indeed working correctly, and that the issue just has to do with my environment and .zshrc somehow.
Update
I discovered jEnv and tried to use that instead of aliases.
Unfortunately, that results in the same problem:
$ brew install openjdk#8
$ jenv add /usr/local/opt/openjdk#8/libexec/openjdk.jdk/Contents/Home
openjdk64-1.8.0.312 added
1.8.0.312 added
1.8 added
$ jenv local 1.8
$ jenv versions
system
* 1.8 (set by /Users/my-username/my-project-dir/.java-version)
1.8.0.312
15
15.0
15.0.1
17
17.0
17.0.1
openjdk64-1.8.0.312
openjdk64-17.0.1
oracle64-15.0.1
$ java --version
Unrecognized option: --version
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Oh, my goodness… The answer was in front of my nose all along:
"Unrecognized option: --version"
With Java 8, the command --version is invalid. Instead, I had to use -version. Newer versions of Java support both commands (with one or two -), which threw me off.
$ jenv global 17
$ java --version
openjdk 17.0.1 2021-10-19
OpenJDK Runtime Environment Homebrew (build 17.0.1+1)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.1+1, mixed mode, sharing)
$ java -version
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment Homebrew (build 17.0.1+1)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.1+1, mixed mode, sharing)
$ jenv global 1.8
$ java --version
Unrecognized option: --version
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
$ java -version
openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-bre_2022_01_01_23_04-b00)
OpenJDK 64-Bit Server VM (build 25.312-b00, mixed mode)
That's the dumbest mistake I've made in a while.

installation error for elasticsearch on windows7

I have been trying to setup elasticsearch in windows7 machine by following https://www.elastic.co/guide/en/elasticsearch/reference/current/_installation.html
I was able to download, unzip but when running ./elasticsearch, I get the below error,
Error: Could not find or load main class
org.elasticsearch.tools.JavaVersionChecker
Elasticsearch requires at least Java 8 but your Java version from C:\Program
Files\Java\jdk1.8.0_131/bin/java does not meet this requirement
I have verified Java versions installed and they look fine,
$ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
$ javac -version
javac 1.8.0_131
Can someone point out where I am wrong ?
In run Elasticsearch in Windows, you should run with elasticsearch.bat not ./elasticsearch directly:
And now we are ready to start our node and single cluster (Windows users should run the elasticsearch.bat file):
Seems like you don't have right permissions. Try to set them to 774 and check again:
sudo chmod 774 -R elasticsearch-6.3.2/

Why is Git Bash not using the correct Java path as defined in the PATH environment variable?

In an instance of Git Bash, typing in java -version gives me:
Error: could not open 'C:\Program Files (x86)\Java\jre7\lib\i386\jvm.cfg'
However, my actual Java path is in D:\Program Files\Java\jdk1.8.0_45\bin. This is shown in my %PATH% variable if I type in either echo $PATH or env | grep PATH.
Where is Git Bash getting this nonexistent Java path from?
P.S.
To add on to this, running java -version in the Command Prompt gives me the correct output:
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
Check if you have some old java.exe, javaw.exe, javaws.exe in the c:/windows/system32 folder, as mentioned in "Java path..Error of jvm.cfg".
I just checked with Git 2.6.3 on Windows, where I don't have anything in c:/windows/system32, and the result is consistent between:
git bash:
vonc#bigvonc MINGW64 /
$ java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
and CMD:
C:\prgs\git\PortableGit-2.6.3-64-bit>java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
Both report the same java at the same spot:
vonc#bigvonc MINGW64 /
$ which java
/c/prgs/jdk/jdk-7u51-windows-x64/bin/java
C:\prgs\git\PortableGit-2.6.3-64-bit>which java.exe
C:\prgs\jdk\jdk-7u51-windows-x64\bin\java.exe
Conclusion: upgrade to the latest git for windows.
If you are trying to manually set JDK, then please check if you haven't missed the Oracle Java (C:\ProgramData\Oracle\Java\javapath) in Path Environment Variable under System Variables, remove it and java -version should work just fine.
Check the PATH variable in your .bash_profile file to make sure it reflects the correct version of java. The file is usually in your home directory C:\Users\\{HOME}\\.bash_profile
It will happen when you have running an IDE with another set of JDK instances. The better way to resolve this is set you JDK home in path and make it available in last row. This is working for me.

Hadoop: JAVA JPS tool not working

I have the Hadoop installed everything looks working fine, except jps.
every time run jps,(I have Oracle Java jdk1.8.0_31 installed) I get this:
The program 'jps' can be found in the following packages:
* openjdk-7-jdk
* openjdk-6-jdk
Try: sudo apt-get install <selected package>
anyone can help? really appreaciate.
here is my java version:
java -version
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
Write "which java", you'll get the path to your java, and in the bin directory look for "jps".
If you find jps there then, perform the below step:
ln - s /usr/bin/jps
OR
You can add bin directory to the class path

java version and PATH on OS X

I'm not sure why my PATH is not being respected regarding where to find java on my MAC OS X 10.9.5.
After searching around I found that the Java version referenced from the command line was at /usr/bin/java, while the Java version referenced by Oracle's tools used by browsers and visible at System Preferences > Java, Open the Java Control Panel, click on Java tab at top, click on View... button, check both User and System tabs for Path, showing in both:
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
The command line picks up 1.6.0_65 even though that is for the version at /usr/bin rather than the one at /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin earlier in the path.
Joes-MacBook-Pro:~ josephmurray$ java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
Joes-MacBook-Pro:~ josephmurray$ which java
/usr/bin/java
Joes-MacBook-Pro:~ josephmurray$ echo $PATH
/Applications/tr-sub.app/Contents/MacOS:/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin:~/civix:/usr/local:/usr/local/bin:/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php/php5.4.19/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/usr/local/git/bin:/usr/X11/bin:/Library/PostgreSQL/9.3/bin/
Joes-MacBook-Pro:~ josephmurray$ /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
Joes-MacBook-Pro:~ josephmurray$ /usr/bin/java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
Joes-MacBook-Pro:~
This is preventing me from installing eclipse because it needs Java to be at least 1.7. How can I fix this?
If you want to work with Eclipse, you need to install a full JDK, not use a JRE. The installed JRE is lacking debug symbols etc.
You can install it from Oracle's Java SE Development Kit download page.
You will then also be able to use command line tools such as javac.
The problem turned out to be using a backslash to escape the space in the path. While using it is necessary when entering a command on the commandline, it should not be included when setting PATH in ~/.bash_profile:
export PATH="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin:~/civix:/usr/local:/usr/local/bin:/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php/php5.4.19/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/usr/local/git/bin:/usr/X11/bin"
export PATH=/Applications/tr-sub.app/Contents/MacOS:$PATH:/Library/PostgreSQL/9.3/bin/
NB: Each time you edit ~/.bash_profile you need to refresh the environment variables in the shell by running:
$ source ~/.bash_profile

Categories