UBUNTU 16.04: How to set JAVA_HOME for Java?

19,770

If you installed java from ppa it sets JAVA_HOME locally in:

/etc/profile.d/jdk.sh

which is added to env on user login. You can edit this file or if you use etckeeper better way is to checkout this file to any version you require.

Share:
19,770

Related videos on Youtube

emax
Author by

emax

Updated on September 18, 2022

Comments

  • emax
    emax over 1 year

    I am following this How to set JAVA_HOME for Java? in order to set the environment variable JAVA_HOME to the correct version. I have different versions of java in my /usr/lib/jvm/folder as illustrated in the following picture.

    enter image description here

    I added JAVA_HOME="/usr/lib/jvm/java-8-oracle"to the environment file.

    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-oracle"
    export JAVA_HOME
    

    however if I run google-refine I have the following error:

    ./refine: 98: [: /tmp/refine.S4a2EGD: unexpected operator
    Google Refine requires Java version 6 or later. If you have multiple versions of Java installed, please set the environment variable JAVA_HOME to the correct version.
    
    • usmanayubsh
      usmanayubsh over 6 years
      It's so hard to read that text in the second picture, can you please edit and copy paste those three lines in your question?
    • emax
      emax over 6 years
      @usmanayubsh I replaced the figure with the text of the file.
    • Redbob
      Redbob over 6 years
      Please execute these commands to check: java -version and printenv | grep JAVA_HOME. If $JAVA_HOME gives nothing, you must add new PATH definition at end of these files: ~/.bashrc and ~/.profile
    • emax
      emax over 6 years
      @Redbob If I type java -version I have 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) while after printenv | grep JAVA_HOME I have JAVA_HOME=/usr/lib/jvm/java-8-oracle
    • Redbob
      Redbob over 6 years
      Please execute this sudo update-alternatives --display java. Maybe Google-refine is not understanding your Default Java, or it will work better with JDK (you are running JRE). If the result of this command above is not as expected, visit this page to adjust your java environment
    • emax
      emax over 6 years
      @Redbob I have java - auto mode link best version is /usr/lib/jvm/java-8-oracle/jre/bin/java link currently points to /usr/lib/jvm/java-8-oracle/jre/bin/java link java is /usr/bin/java slave java.1.gz is /usr/share/man/man1/java.1.gz /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java - priority 1081 slave java.1.gz: /usr/lib/jvm/java-8-openjdk-amd64/jre/man/man1/java.1.gz /usr/lib/jvm/java-8-oracle/jre/bin/java - priority 1081 slave java.1.gz: /usr/lib/jvm/java-8-oracle/man/man1/java.1.gz
    • Redbob
      Redbob over 6 years
      Possibly Oracle Java has no priority to Google-refine, even if JAVA_HOME is settled. Follow these instructions to establish Oracle Java as priority to your system. In my case, I'd rather to uninstall all other and left only Oracle Java.
    • Gunnar Hjalmarsson
      Gunnar Hjalmarsson over 6 years
      Side comment: That line export JAVA_HOME is redundant. /etc/environment is not a script file.