简体   繁体   中英

JAVA_HOME Ubuntu Terminal

I really tried to avoid this question since there are already a lot of it. However I could just not fix to set the my terminal to the right JAVA_HOME.

First here the following outputs:

Java-Home

echo $JAVA_HOME
/usr/lib/jvm/java-7-oracle

Java-Version:

java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Maven-version:

mvn -version
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/java-7-oracle/bin/java

Installed-Java-Version:

/usr/lib/jvm$ ls -l
total 8
lrwxrwxrwx 1 root root   24 Mär 22  2014 default-java -> java-1.7.0-openjdk-amd64
lrwxrwxrwx 1 root root   20 Nov 19  2015 java-1.7.0-openjdk-amd64 -> java-7-openjdk-amd64
drwxr-xr-x 5 root root 4096 Jan 26  2016 java-7-openjdk-amd64
drwxr-xr-x 8 root root 4096 Mai  7  2016 java-8-oracle

We can see that the default java-version is set to 1.7. However the version displayed with java --version is 1.8 and maven (as well as other applications) is unable to locate any correct one.

I tried the following things:

  • set JAVA_HOME in etc/environment for systemwide
  • set JAVA_HOME in profile.d (jvm and jdk)
  • set JAVA_HOME in a self-constructed .bashrc file in /etc/
  • set JAVA_HOME in a self-constructed .bashrc file in usr-home-directory
  • set JAVA_HOME in dot.bashrc file in /etc/
  • change the default java version with config alternatives:

    :

    sudo update-alternatives --config java There are 2 choices for the alternative java (providing /usr/bin/java).

      Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1075 auto mode 1 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode 2 /usr/lib/jvm/java-8-oracle/jre/bin/java 1075 manual mode 

When I set JAVA_HOME manually in the terminal it changes the variable for the session of the terminal but still does not work:

export JAVA_HOME=JAVA_HOME=/usr/lib/jvm/java-8-oracle
echo $JAVA_HOME
JAVA_HOME=/usr/lib/jvm/java-8-oracle

java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

mvn -version
Error: JAVA_HOME is not defined correctly.
  We cannot execute JAVA_HOME=/usr/lib/jvm/java-8-oracle/bin/java

It would be awesome if someone can bring me some light into all of it. As I understood the system-wide variables are set in the /etc/environment and for the bash usually the profile.d should be loaded or I just set it in bashrc so it gets loaded each time when the terminal is initialized?

Kind regards

Did you also set your PATH variable to correct java required? I guess your PATH and JAVA_HOME are pointing to different JDKs. This must be the reason for different output of java -version and echo $JAVA_HOME.

Also are you using JRE for JAVA_HOME? I think it should be JDK.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM