Setting PATH env on Linux [duplicate] - java

This question already has answers here:
JAVA_HOME and PATH are set but java -version still shows the old one
(10 answers)
Closed 4 years ago.
I tried installing java on Amazon linux.
I installed jdk 1.8.0 and I changed PATH to .bash_profile
export JAVA_HOME=/home/.../jdk1.8.0_192
export PATH=$JAVA_HOME/bin:$PATH
but java -version still returns old java version (1.7.0)
I checked the result was JAVA_HOME = /usr/lib/jvm/jre
if I check which java then the result is /usr/bin/java
how to change the java version to the new one?

you need to type below command on shell
sudo update-alternatives --config java
It will display all available JRE and you need to type the number which java you want to select(You can perform this for javac also).

Related

Java Version check in Command Prompt [duplicate]

This question already has answers here:
java --version doesn't work in the command line
(2 answers)
Closed 10 months ago.
I am using a 32 bit windows 7 OS and I have installed JDK 8 as it was the only available JDK version for a 32 bit system. I have also given the path in the environment variables. But, when I am trying to check the java version in the command prompt typing java --version, I am getting a fatal error.
You should double check if your path variable is set correctly. It should point to the ...\bin\ directory where the 'java.exe' is located. Because thats whats called with 'java --version'.

JAVA_HOME should point to a JDK not a JRE even though it points to a JDK [duplicate]

This question already has answers here:
JAVA_HOME should point to a JDK not a JRE
(25 answers)
Closed 4 years ago.
Hello and thank you for any help you can provide.
I just upgraded to Ubuntu 18.04.1 and before the install my JAVA_HOME for my path was defined properly and worked successfully. However, I am now unable to use Maven due to the following error: "JAVA_HOME should point to a JDK not a JRE". I know this is a common problem and I tried a lot of potential solutions before making this post.
When I echo $JAVA_HOME, I get back /usr/lib/jvm/java-11-openjdk-amd64/bin which is what I set it to be in my .bashrc via the following lines:
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/bin
export JAVA_HOME
PATH=$PATH:$JAVA_HOME
export PATH
From there, I also checked Which java where I got the output of /usr/bin/java. I checked further and found that readlink -f /usr/bin/java returns a value of /usr/lib/jvm/java-11-openjdk-amd64/bin/java. Again, this points to a JDK not a JRE.
I also attempted to fix the issue by configuring a java with sudo update-alternatives --config java and chose the value of /usr/lib/jvm/java-11-openjdk-amd64/bin/java
To top it all off, I have reinstalled java and maven and I have restarted my computer and command line multiple times.
First, try and remove the /bin from your JAVA_HOME path.
You should reference the main folder of the JDK, not its bin/ subfolder.
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64

how to change java -version on windows to show Java 1.9 [duplicate]

This question already has answers here:
How to set java_home on Windows 7?
(18 answers)
Closed 4 years ago.
I have java 1.9 installed on my machine. I can see it in installed programs. But when i type java -version on command prompt it still shows 1.8. How can i change it ?
I assume you meant 1.8
Windows and Linux allow multiple JRE to be installed. They have different mechanisms for determining which JRE is used by default. Basically, it comes down to your system path.

Error while checking the java version in command prompt [duplicate]

This question already has answers here:
How to set the environment variables for Java in Windows
(17 answers)
Closed 5 years ago.
On my windows 7, 64 bit pc, I have installed java but while typing java -version in command prompt it shows java' is not recognized as an internal or external command, operable program or batch file.".and there is no java folder in program files even.The java version which i have installed is 8 and it is 64bits.
Try setting the environment variables.
The answer can be found on this SO page.
You must install the latest version of JDK from here:
Download JDK From Here
After Installing the latest version follow these steps :
Setting Path in Java
Hope this will help you out.

Ubuntu 14.04 - Oracle JDK 8 - Where is the JAVA_HOME environment variable defined? [duplicate]

This question already has answers here:
Ubuntu: change the path from OpenJDK 6 to Oracle JDK 7
(5 answers)
Closed 6 years ago.
I am trying to uninstall Oracle jdk 8 on my Ubuntu 14.04 server, in order to replace it with open jdk 8 because open source ftw. I have run apt-get purge, apt-get autoclean, logged out, logged back in, and when I run the env command, I see the following:
JAVA_HOME=/usr/lib/jvm/java-8-oracle
I do not want to overwrite this value in my .bashrc file, I do not want to take shortcuts or apply band aids, I want to fix the problem at the source by finding where it is set and removing it. Please help
I found the solution. I ran the following command to find files with the old jdk path:
sudo find / -type f -exec grep -Flm 1 '/usr/lib/jvm/java-8-oracle' {} +
The culprits were in the following directory:
/etc/profile.d

Categories