Change Java version terminal uses - java

my first post on this forum, so please give me a break. Recently I installed java 7 for my computer, but I had downloaded java 6 before. Currently the Java control panel and the java website tells me that I have Java 7. However, when I go into the terminal and type: java -version, it comes up with:
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)
I am aware that terminal accesses java from the path '/usr/bin/java', and the control panel accesses java from the path '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java', so how can I change the terminal path to java?

Try using $ export JAVA_HOME=$(/usr/libexec/java_home -v 1.7) - it's the canonical way to switch Java versions.
Here's what it looks like on my machine:
$ export JAVA_HOME=$(/usr/libexec/java_home -v 1.6)
$ 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)
$ export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
$ java -version
java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

Related

How to set Java -version is returning jdk instead if java

Hello I installed java on my MacOS but its not working as expected.
When I do java -version below is the output I am getting instead of right version number:
abc#xxxxx ~ % java -version
openjdk version "15" 2020-09-15
OpenJDK Runtime Environment AdoptOpenJDK (build 15+36)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 15+36, mixed mode, sharing)
I see this is want installed under system and user:
Expected Output:
1234$ java -version
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode)
Perhaps you should fix your JAVA_HOME.
Here's the easiest way I know. Just add this to your ~/.bash_profile and ~/.zshenv:
export JAVA_HOME="$(/path/to/your/java)"
Then restart your terminals/IDEs.

java 11, running sdkmanage results in java.lang.module.FindException: Module java.se.ee not found

i tried
export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'
and some old solutions here for java 9 same error but nothing work. please help
OS: mac. java version:
Users-MacBook-Pro:Users user$ java --version
java 11.0.2 2019-01-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)
open sdkManager:
Users-MacBook-Pro:~ user$ /Users/user/android/tools/bin/sdkmanager ; exit;
Error occurred during initialization of boot layer
java.lang.module.FindException: Module java.se.ee not found
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
[Process completed]
EDIT - MORE DATA:
I installed java 8 as well and run this command:
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`; java -version
and got:
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)
But sdkmanage still gives the same error.
By the way, when close an open again the terminal, running java -version results again with:
java version "11.0.2" 2019-01-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)
Is it OK?
UPDATE 1.4
I have change the .bash_profile file to this:
export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_202`
unset JAVA_OPTS
and running env give:
Users-MacBook-Pro:~ user$ env
TERM_PROGRAM=Apple_Terminal
SHELL=/bin/bash
TERM=xterm-256color
TMPDIR=/var/folders/9t/4jx8w7_s6f5blrh1yly746z80000gn/T/
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.gDNTyh8LPx/Render
TERM_PROGRAM_VERSION=404.1
TERM_SESSION_ID=8F5607E3-18FE-467B-B843-58F71D03F9B0
USER=user
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.jY4TgxEWu3/Listeners
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
PWD=/Users/user
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
SHLVL=1
HOME=/Users/user
LOGNAME=user
LC_CTYPE=UTF-8
_=/usr/bin/env
Users-MacBook-Pro:~ user$
running sdk manager still give the same error
I had the same problem and I did this:
export APP_HOME=/path/to/my/java-8
export JAVA_HOME=/path/to/my/java-8
On the other hand, if you want to keep this configuration on reboot or in other terminal, you must put these lines on ~/.bashrc file

VsCode does not indicate the correct version

Why not specified correct version of java JRE in my vscode ?
Here is my java version.
$java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
And env path here,
$env | grep JAVA
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home
And user setting in vscode,
"java.home": "/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home",
When open java project in vscode, next error occurred.
enter image description here
Hello.Thank you.

rt.jar Java Scan on Red Hat Server

I'm looking for a way to run a scan of all rt.jar on my Red Hat 6 server and then find out what version of java I'm using in each of these directories. I notice sometimes if the directory doesn't list the version on the folder I'm at lost. I assume I can use ' sudo find / -name rt.jar ' to find all the rt.jar but how can I check each java version of these rt.jar files ?
Example :
[admin:/ryan/vacation-linux/bin]
(admin)$ sudo find / -name rt.jar
/ryan/jre1.8.0_171_linux/lib/rt.jar
/bob/jre1.6.0_171_linux/lib/rt.jar
/charles/java/lib/rt.jar
Thanks,
Ryan
Use find combined with awk to generate a java -version command to run:
sudo find /Library/Java/JavaVirtualMachines -name rt.jar | awk -v OFS='/' -F '/' '{$(NF)="" ; printf("echo %s && %s../bin/java -version && echo && echo\n", $0, $0)}' | sh
For me, that prints:
/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
/Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk/Contents/Home/jre/lib/
java version "1.8.0_141"
Java(TM) SE Runtime Environment (build 1.8.0_141-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.141-b15, mixed mode)
/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

Installing eclipse mars on Linux

I just downloaded the linux 64 bit tar for eclipse mars. When I try and run the installer it gives me the following message
Version 1.6.0_31 of the JVM is not suitable for this product.
Version: 1.7 or greater is required.
I am on java version 1.8. See
$java -version
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
Where does it get the 1.6 version of java?
.cshrc.mine
setenv $JAVA_HOME /path/to/Java8
setenv PATH /path/to/Java8/bin/:$PATH
Also
$ java -XshowSettings:properties -version
Property settings:
// Other props
java.runtime.name = Java(TM) SE Runtime Environment
java.runtime.version = 1.8.0_65-b17
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
Try specify the JDK/JRE path by adding the following two lines into the beginning of your eclipse.ini file:
-vm
[your-path-to-java-executable]
In your eclipse.ini file you should point to java8
-vm
/opt/jdk18025/bin/javaw.exe

Categories

Resources