Java -version error - java

I have installed JDK 1.8 on my ubuntu 16.04, for some kind of work I had to install JDK 1.7.I installed it without did anything to my older version and changed the $JAVA_HOME to point the newly installed location.
echo $JAVA_HOME works fine , showing newly installed version which is 1.7
but when I do $ java -version it shows earlier installed version which is 1.8.
Why does this happen? How to resolve it.
I need 1.7 to work with it further.
If I went wrong in somewhere please correct me,I need good explanation regarding this.
Thank you.
here is my terminal

Try to run following command in terminal:
$ sudo update-alternatives --config java
It shows installed alternatives for java command. You can choose which one you will use by default further on.

Related

Appium Setup - Determining what jdk version I am using on mac

I am following a guide to set up Appium on my mac. It is asking me to set my JAVA_Home variables. They are using: export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home
They have instructed me to replace jdk1.8.0_192.jdk with my own version of JDK.
How would I find out what my JDK is?
I have tried using: java -version
java version "11.0.11" 2021-04-20 LTS
I am unsure how to translate that into the correct JDK.
Thanks in advance for any help
For the currently used jdk version;
/usr/libexec/java_home -V
You can use this command.
I was able to find the jdk version using the below command:
ls /Library/Java/JavaVirtualMachines

How to downgrade Java -version in Mac

tried the below commands in Mac Terminal and did not update the java version:
/usr/libexec/java_home -V
export JAVA_HOME=“System/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home”
Updated again
Fixed it ! export JAVA_HOME=`/usr/libexec/java_home -v 11.0.8` worked
note:
please use ` and not ' in your terminal command.
also only: /usr/libexec/java_home takes effect and not the System/Library/Java/JavaVirtualMachines/.
Verified version afterwards using:
Java -version
validated and all good now.
Downgraded! Yay!
Welcome to SO!
Even though you already solved it, using sdkman greatly reduces stress if you want to switch regularly between versions.

Editing PATH for Java

I am using Manjaro GNU/Linux 5.7.0-3 x86_64 and had installed older Java Oracle jdk1.8 previously but now I want to install Oracle jdk14.0.1 which I have unpacked to /opt.
In order to reflect the changes, I edited ~/.bashrc file by adding this line:
export PATH="/home/arjun/anaconda3/condabin:/home/arjun/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/jdk-14.0.1/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl"
Then executed these to reload the terminal:
source ~/.bashrc
bash;
And I even restarted the computer but still, Java is using the older version:
$ javac -version
javac 1.8.0_252
What's going wrong?
Thanks!
In ArchLinux and manjaro you can use pre-installed archlinux-java utility.
for getting information about all installed java's and current choice, you need status and for change it you can use set
sudo archlinux-java status
sudo archlinux-java set java-14-jdk # or something similar related to java14
read more about it in the wiki
Because of different versions of java are installed, you can change default option with this command.
sudo update-alternatives --config java
With this command, you can select java version as default option.

Removing JDK/NetBeans from Debian

I am new to Linux and new to Java.
Previously i had jdk1.8.0_171 installed, along with netbeans 8.2.
During one of the Kali updates, JDK 8 was completely replaced by JDK 10.
As a result of that, netbeans stopped functioning.
I attempted to install JDK 8, and it seemed to work.
java -version
was showing both 8 and 10 after using
sudo update-alternatives --config java
to select different versions.
That however had no effect on netbean, it was completely unusable.
Then i made a decision to completely remove everything that had to do with Java, and install a fresh copy of JDK 8.
sudo apt-get purge openjdk*
and
sudo apt-get purge icedtea*
was used.
java -version and sudo dpkg --list|grep -i jdk
was used to make sure nothing was left.
Additionally running
apt-get update
removed some unused leftovers.
Next i downloaded and executed jdk 8_171 tar.gz file. It ran, but gave some error in the end.
Next i tried to remove Netbeans, but received a message saying that i would need JDK to be installed to do anything about Netbeans.
java -version
showed nothing. Purging of both openjdk and icedtea did nothing, both say that files are not present.
Then i have tried to install JDK + Netbean combo, and that resulted in error message saying that JDK is already installed.
So now i am in the situation where i cant remove Netbean, Netbean is not working because JDK is not present. JDK cant be installed because apparently i already have JDK. Where JDK was installed i cant figure out, searching manually and with using
whereis name
is not yielding any meaningful results.
Detailed explanation on what is going on and what should i do about it would be greatly appreciated.

Choose updated Java SDK in mac from available different version

I'm using mac machine for native-script development and while executing an program it thrown an java error that:
Javac version 1.6.0_65 is not supported. You have to install at least 1.8.0.
so I checked with available install version on developer machine & found two different version detail:
/usr/bin/java -version Showing 1.6.
while system preference -> java control panel -> update. showing V1.8
any suggestion why two version !! Am I missing something here?
Update1: Following help to understand how mac handling this: /usr/bin/java is machine default location, and /Library/Internet.. which is manage explicit.
sudo rm /usr/bin/java
sudo ln -s /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java /usr/bin
In my case I update default one with downloaded from internet.
Reference link Link1, Link2
You should use /usr/libexec/java_home instead
> /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
you can use it to set JAVA_HOME
export JAVA_HOME=$(/usr/libexec/java_home)
then, you can put this one inside ~/.profile so you have always JAVA_HOME set to most recent release.

Categories

Resources