conda environment with wrong java version - java

I created a new conda environment with the command conda create --name condaenv python=2.7 openjdk=8. When I activate this environment using conda activate condaenv and check the java version, however, I get:
openjdk version "1.7.0_91"
OpenJDK Runtime Environment (Zulu 7.12.0.3-linux64) (build 1.7.0_91-b15)
OpenJDK 64-Bit Server VM (Zulu 7.12.0.3-linux64) (build 24.91-b15, mixed mode)
How can I get the correct java version for this conda environment?
I checked that the JAVA_HOME environmental variable is correct, and it is since running echo $JAVA_HOME gives /home/ag956/.conda/envs/condaenv

I solved the issue by first installing Java 1.8 with the command:
conda install -c main java-1.8.0-openjdk-cos7-s390x
And then creating the environment.

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.

java command not running from JAVA_HOME on Mac Caralina

I installed java 8 and openjdk 11 on my Mac. JAVA_HOME is set to java 8, but when running java --version, it points to openjdk 11. Why is it happens and how can I make java command point to java 8?
running the command
echo $JAVA_HOME
java --version
output is
/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home
openjdk 11.0.8 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+11)
OpenJDK 64-Bit Server VM (build 11.0.8+11, mixed mode)
It is so wired.
export PATH=${JAVA_HOME}:${PATH}
Add this to ~/.zshrc. JAVA_HOME will be the first choice when running java.

How to configure JDK environment path not JRE?

I have install JDK 8 and my environment path is
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
JAVA_HOME="/usr/lib/jvm/java-8-openjdk"
PATH=$PATH:/usr/lib/jvm/java-8-openjdk/bin
Here is my Java version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-0ubuntu0.18.04.1-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
I am getting problem while installing Maven on Ubuntu
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
Just run update-alternatives --config java this should gives you the path to the java home.
After this you can set your JAVA_HOME path simply. Just edit your ~/.bashrc and add this line export JAVA_HOME=<path_given_by_the_command above>. After this reload your bashrc.
Once you have installed oracle JDK on your Ubuntu then run below command to set JDK as default
sudo apt install oracle-java8-set-default
This will set environment variable path and you don't need to change config files manually.
Try getting the path using readlink
export JAVA_HOME="$(readlink -f /etc/alternatives/java | sed -e 's/\/jre\/bin\/java$//')"

JAVA_HOME is not defined correctly. ubuntu

When I check maven Version
$ mvn -version
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/java-8-oracle/bin/java
How to solve it ?
these are my java jdk version.
$ java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-0ubuntu0.18.04.1-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
$ echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle
Make sure your JAVA_HOME variable is set to the JRE folder, like this:
/usr/lib/jvm/java-8-oracle/jre
To further improve your setup, you can let Java pick the correct version by putting this in your JAVA_HOME (this assumes you used the Oracle installer):
export JAVA_HOME=$(/usr/libexec/java_home)
If this doesn't work for you, make sure permissions are set correctly (Execute permissions on the binaries)

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.

Categories