Error: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java 11 openjdk-amd64 bin/java

Error: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-8-oracle/jre/bin/java when i run gradle command in terminal



On a 64bit openSuse 64 42.1 box;

readlink -f $(which java)

provided;

/usr/lib64/jvm/java-1.8.0-openjdk-1.8.0/jre/bin/java

But;

export JAVA_HOME=/usr/lib64/jvm/jre-1.8.0-openjdk


in terminal run sudo nano /etc/environment and add the line JAVA_HOME="/usr/lib/jvm/java-12-oracle"

Then open terminal and run export JAVA_HOME="/usr/lib/jvm/java-12-oracle"


You need to login first then you can post Your Answer Log in Sign up

728x90

왠지 모르게 어느날부터 자바 셋팅이 꼬였는데 일단 gradle도 안되는 상황 ㅠㅠ 

개발 환경

mac -> vscode -> ssh -> remote linux server 

맥에서 vscode로 리눅스 서버 접속 (remote extension  사용) 

우선 jdk는 서버에 설치가 잘 되어 있는 상황이었다. (javac --version) 하니까 잘나옴

1. $ which java 

/usr/bin/java

2. $ readlink -f /usr/bin/java

/usr/lib/jvm/java-11-openjdk-amd64/bin/java

여기서 뒤에 bin/java는 뺴야함

3. sudo vi /etc/bash.bashrc

export JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64/"

4. source /etc/bash.bashrc

5. reload 

이랬더니 다니 gradle 이 되긴 한다..

728x90

'기술 > Linux' 카테고리의 다른 글

Linux) iptables란?  (0) 2022.01.04
Linux/Java/VSCode) Gradle -> ERROR: JAVA_HOME is set to an invalid directory: 해결  (0) 2021.08.23
Linux/vscode) vscode로 remote 환경 연동, Error: EACCES: permission denied 에러 해결  (0) 2021.07.09
리눅스/Ubuntu) 80포트 8080으로 포워딩 하기  (0) 2021.06.30
리눅스/Ubuntu) Huge page 관련 실험 과정  (0) 2021.04.13
리눅스/Linux) Ubuntu THP 활성화 / 비활성화 ~/transparent_hugepage/enabled  (0) 2021.04.13

  • Error: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java 11 openjdk-amd64 bin/java
  • Forum
  • The Ubuntu Forum Community
  • Ubuntu Official Flavours Support
  • General Help
  • [SOLVED] How to fix "JAVA_HOME is set to an invalid directory"

  1. How to fix "JAVA_HOME is set to an invalid directory"

    Hi all,

    I was following below document to install Whatsapp on Ubuntu 18.04;
    Run WhatsApp on Android SDK without a phone
    https://eureka.ykyuen.info/2012/02/0...thout-a-phone/

    Installation went throught without much problem. On starting Avdmanger;

    $ ./Android/Sdk/tools/bin/avdmanager

    Code:

    ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-7-oracle Please set the JAVA_HOME variable in your environment to match the location of your Java installation.

    $ la -al /usr/lib/jvm/default-java

    Code:

    lrwxrwxrwx 1 root root 25 Apr 8 2018 /usr/lib/jvm/default-java -> java-1.11.0-openjdk-amd64

    $ la -al /usr/lib/jvm/

    Code:

    total 28 drwxr-xr-x 5 668 668 4096 Nov 2 12:58 . drwxr-xr-x 131 root root 4096 Nov 2 14:46 .. lrwxrwxrwx 1 root root 25 Apr 8 2018 default-java -> java-1.11.0-openjdk-amd64 lrwxrwxrwx 1 root root 21 Oct 7 23:06 java-1.11.0-openjdk-amd64 -> java-11-openjdk-amd64 -rw-r--r-- 1 root root 2619 Oct 7 23:06 .java-1.11.0-openjdk-amd64.jinfo drwxr-xr-x 7 root root 4096 Nov 2 12:56 java-11-openjdk-amd64 lrwxrwxrwx 1 root root 20 Oct 23 01:29 java-1.8.0-openjdk-amd64 -> java-8-openjdk-amd64 -rw-r--r-- 1 root root 2600 Oct 23 01:29 .java-1.8.0-openjdk-amd64.jinfo drwxr-xr-x 5 root root 4096 Nov 2 12:58 java-8-openjdk-amd64 drwxr-xr-x 8 668 668 4096 Nov 1 23:26 jdk-11.0.1

    $ ls /usr/lib/jvm/java-11-openjdk-amd64/

    Code:

    bin conf docs legal lib man

    $ java --version

    Code:

    openjdk 10.0.2 2018-07-17 OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.3) OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.3, mixed mode)

    Please advise how to fix the problem? Thanks in advance

    Regards
    satimis


  2. Re: How to fix "JAVA_HOME is set to an invalid directory"

    In a terminal window

    Code:

    export JAVA_HOME=java_home_path # java_home_path being the folder where your bin/java is.


  3. Re: How to fix "JAVA_HOME is set to an invalid directory"

    Error: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java 11 openjdk-amd64 bin/java
    Originally Posted by slickymaster
    Error: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java 11 openjdk-amd64 bin/java

    In a terminal window

    Code:

    export JAVA_HOME=java_home_path # java_home_path being the folder where your bin/java is.

    Hi,

    Thanks for your advice.

    $ sudo find / -name java | grep bin

    Code:

    /home/satimis/Android/Sdk/sources/android-28/android/databinding/tool/reflection/java /home/satimis/android-studio/jre/bin/java /home/satimis/android-studio/jre/jre/bin/java find: ‘/run/user/1000/gvfs’: Permission denied /usr/bin/java /usr/lib/jvm/java-8-openjdk-amd64/bin/java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/lib/jvm/jdk-11.0.1/bin/java

    Which path shall I use;
    1.

    Code:

    /home/satimis/android-studio/jre/bin/java

    $ ls -al /home/satimis/android-studio/jre/bin/

    Code:

    total 660 drwxrwxr-x 2 satimis satimis 4096 Oct 8 21:12 . drwxrwxr-x 6 satimis satimis 4096 Oct 8 21:12 .. -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 appletviewer -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 extcheck -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 idlj -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 jar -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 jarsigner -rwxr-xr-x 1 satimis satimis 8520 Oct 8 18:35 java -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 javac -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 javadoc -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 javah -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 javap -rwxr-xr-x 1 satimis satimis 2806 Oct 8 18:35 java-rmi.cgi -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 jcmd -rwxr-xr-x 1 satimis satimis 8656 Oct 8 18:35 jconsole -rwxr-xr-x 1 satimis satimis 8648 Oct 8 18:35 jdb -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 jdeps -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 jhat -rwxr-xr-x 1 satimis satimis 8680 Oct 8 18:35 jinfo -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 jjs -rwxr-xr-x 1 satimis satimis 8680 Oct 8 18:35 jmap -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 jps -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 jrunscript -rwxr-xr-x 1 satimis satimis 8648 Oct 8 18:35 jsadebugd -rwxr-xr-x 1 satimis satimis 8680 Oct 8 18:35 jstack -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 jstat -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 jstatd -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 keytool -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 native2ascii -rwxr-xr-x 1 satimis satimis 8688 Oct 8 18:35 orbd -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 pack200 -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 policytool -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 rmic -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 rmid -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 rmiregistry -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 schemagen -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 serialver -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 servertool -rwxr-xr-x 1 satimis satimis 8688 Oct 8 18:35 tnameserv -rwxr-xr-x 1 satimis satimis 182336 Oct 8 18:35 unpack200 -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 wsgen -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 wsimport -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 xjc


    Or

    2.

    Code:

    /home/satimis/android-studio/jre/jre/bin/java

    $ ls -al /home/satimis/android-studio/jre/jre/bin/

    Code:

    total 308 drwxrwxr-x 2 satimis satimis 4096 Oct 8 21:12 . drwxrwxr-x 4 satimis satimis 4096 Oct 8 21:12 .. -rwxr-xr-x 1 satimis satimis 8520 Oct 8 18:35 java -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 jjs -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 keytool -rwxr-xr-x 1 satimis satimis 8688 Oct 8 18:35 orbd -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 pack200 -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 policytool -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 rmid -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 rmiregistry -rwxr-xr-x 1 satimis satimis 8632 Oct 8 18:35 servertool -rwxr-xr-x 1 satimis satimis 8688 Oct 8 18:35 tnameserv -rwxr-xr-x 1 satimis satimis 182336 Oct 8 18:35 unpack200

    Or

    3.

    Code:

    /usr/lib/jvm/java-11-openjdk-amd64/bin/java

    ls -al /usr/lib/jvm/java-11-openjdk-amd64/bin/

    Code:

    total 224 drwxr-xr-x 2 root root 4096 Nov 2 12:56 . drwxr-xr-x 7 root root 4096 Nov 2 12:56 .. -rwxr-xr-x 1 root root 10344 Oct 7 23:06 java -rwxr-xr-x 1 root root 10400 Oct 7 23:06 jjs -rwxr-xr-x 1 root root 10376 Oct 7 23:06 keytool -rwxr-xr-x 1 root root 10408 Oct 7 23:06 orbd -rwxr-xr-x 1 root root 10376 Oct 7 23:06 pack200 -rwxr-xr-x 1 root root 10368 Oct 7 23:06 rmid -rwxr-xr-x 1 root root 10376 Oct 7 23:06 rmiregistry -rwxr-xr-x 1 root root 10376 Oct 7 23:06 servertool -rwxr-xr-x 1 root root 10416 Oct 7 23:06 tnameserv -rwxr-xr-x 1 root root 107456 Oct 7 23:06 unpack200

    Or

    4.

    Code:

    /usr/lib/jvm/jdk-11.0.1/bin/java

    $ ls -al /usr/lib/jvm/jdk-11.0.1/bin/

    Code:

    total 516 drwxr-xr-x 2 668 668 4096 Nov 1 23:26 . drwxr-xr-x 8 668 668 4096 Nov 1 23:26 .. -rwxr-xr-x 1 668 668 12952 Oct 6 20:32 jaotc -rwxr-xr-x 1 668 668 8736 Oct 6 20:32 jar -rwxr-xr-x 1 668 668 8736 Oct 6 20:32 jarsigner -rwxr-xr-x 1 668 668 8672 Oct 6 20:32 java -rwxr-xr-x 1 668 668 8784 Oct 6 20:32 javac -rwxr-xr-x 1 668 668 8784 Oct 6 20:32 javadoc -rwxr-xr-x 1 668 668 8736 Oct 6 20:32 javap -rwxr-xr-x 1 668 668 8736 Oct 6 20:32 jcmd -rwxr-xr-x 1 668 668 12888 Oct 6 20:32 jconsole -rwxr-xr-x 1 668 668 8736 Oct 6 20:32 jdb -rwxr-xr-x 1 668 668 8736 Oct 6 20:32 jdeprscan -rwxr-xr-x 1 668 668 8736 Oct 6 20:32 jdeps -rwxr-xr-x 1 668 668 8736 Oct 6 20:32 jhsdb -rwxr-xr-x 1 668 668 8736 Oct 6 20:32 jimage -rwxr-xr-x 1 668 668 12880 Oct 6 20:32 jinfo -rwxr-xr-x 1 668 668 8784 Oct 6 20:32 jjs -rwxr-xr-x 1 668 668 8784 Oct 6 20:32 jlink -rwxr-xr-x 1 668 668 12880 Oct 6 20:32 jmap -rwxr-xr-x 1 668 668 8736 Oct 6 20:32 jmod -rwxr-xr-x 1 668 668 8736 Oct 6 20:32 jps -rwxr-xr-x 1 668 668 8792 Oct 6 20:32 jrunscript -rwxr-xr-x 1 668 668 8736 Oct 6 20:32 jshell -rwxr-xr-x 1 668 668 12880 Oct 6 20:32 jstack -rwxr-xr-x 1 668 668 8736 Oct 6 20:32 jstat -rwxr-xr-x 1 668 668 8736 Oct 6 20:32 jstatd -rwxr-xr-x 1 668 668 8736 Oct 6 20:32 keytool -rwxr-xr-x 1 668 668 8736 Oct 6 20:32 pack200 -rwxr-xr-x 1 668 668 8736 Oct 6 20:32 rmic -rwxr-xr-x 1 668 668 8736 Oct 6 20:32 rmid -rwxr-xr-x 1 668 668 8744 Oct 6 20:32 rmiregistry -rwxr-xr-x 1 668 668 8736 Oct 6 20:32 serialver -rwxr-xr-x 1 668 668 117656 Oct 6 20:32 unpack200


    ?

    Thanks

    Regards
    satimis

    Last edited by satimis; November 2nd, 2018 at 12:43 PM.


  4. Re: How to fix "JAVA_HOME is set to an invalid directory"

    Depending on what you intend to go, openjdk or pure jdk, use the the third option for the former or the forth for the later


  5. Re: How to fix "JAVA_HOME is set to an invalid directory"

    Error: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java 11 openjdk-amd64 bin/java
    Originally Posted by slickymaster
    Error: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java 11 openjdk-amd64 bin/java

    Depending on what you intend to go, openjdk or pure jdk, use the the third option for the former or the forth for the later

    How to revoke the command

    Code:

    export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/bin/java

    ?

    If unable to start Avdmanger for trying;

    Code:

    export JAVA_HOME=/usr/lib/jvm/jdk-11.0.1/bin/java

    Or just to re-run it ?

    Thanks

    satimis


  6. Re: How to fix "JAVA_HOME is set to an invalid directory"

    You to remove bin/java from the end of the path while putting it into JAVA_HOME. Either

    Code:

    export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/

    or

    Code:

    export JAVA_HOME=/usr/lib/jvm/jdk-11.0.1/


  7. Re: How to fix "JAVA_HOME is set to an invalid directory"

    Error: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java 11 openjdk-amd64 bin/java
    Originally Posted by slickymaster
    Error: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java 11 openjdk-amd64 bin/java

    You to remove bin/java from the end of the path while putting it into JAVA_HOME. Either

    Code:

    export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/

    or

    Code:

    export JAVA_HOME=/usr/lib/jvm/jdk-11.0.1/

    It is very strange. Non of them can work !

    $ export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/java
    $ ./Android/Sdk/tools/bin/avdmanager

    Code:

    ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-11-openjdk-amd64/java Please set the JAVA_HOME variable in your environment to match the location of your Java installation.

    $ export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/
    $ export JAVA_HOME=/usr/lib/jvm/jdk-11.0.1/bin/java
    $ ./Android/Sdk/tools/bin/avdmanager

    Code:

    ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/jdk-11.0.1/bin/java Please set the JAVA_HOME variable in your environment to match the location of your Java installation.


    $ export JAVA_HOME=/usr/lib/jvm/jdk-11.0.1/
    $ export JAVA_HOME=/home/satimis/android-studio/jre/bin/java
    $ ./Android/Sdk/tools/bin/avdmanager

    Code:

    ERROR: JAVA_HOME is set to an invalid directory: /home/satimis/android-studio/jre/bin/java Please set the JAVA_HOME variable in your environment to match the location of your Java installation.


    $ export JAVA_HOME=/home/satimis/android-studio/jre/
    $ export JAVA_HOME=/home/satimis/android-studio/jre/jre/bin/java
    $ ./Android/Sdk/tools/bin/avdmanager

    Code:

    ERROR: JAVA_HOME is set to an invalid directory: /home/satimis/android-studio/jre/jre/bin/java Please set the JAVA_HOME variable in your environment to match the location of your Java installation.


    $ export JAVA_HOME=/home/satimis/android-studio/jre/jre/
    $ export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/bin/java
    $ ./Android/Sdk/tools/bin/avdmanager

    Code:

    ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-8-openjdk-amd64/bin/java Please set the JAVA_HOME variable in your environment to match the location of your Java installation.


    $ export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/
    $ export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
    $ ./Android/Sdk/tools/bin/avdmanager

    Code:

    ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java Please set the JAVA_HOME variable in your environment to match the location of your Java installation.

    Do I need to reboot after running each command?

    Regards
    satimis


  8. Re: How to fix "JAVA_HOME is set to an invalid directory"

    No, a reboot shouldn't be necessary. What do you get out of

    Code:

    $JAVA_HOME/bin/java -version

    and also

    Code:

    readlink -f $(which java)


  9. Re: How to fix "JAVA_HOME is set to an invalid directory"

    Error: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java 11 openjdk-amd64 bin/java
    Originally Posted by slickymaster
    Error: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java 11 openjdk-amd64 bin/java

    No, a reboot shouldn't be necessary. What do you get out of

    Code:

    $JAVA_HOME/bin/java -version

    and also

    Code:

    readlink -f $(which java)


    $ $JAVA_HOME/bin/java -version

    Code:

    bash: /usr/lib/jvm/java-7-oracle/bin/java: No such file or directory

    $ readlink -f $(which java)

    Code:

    /usr/lib/jvm/java-11-openjdk-amd64/bin/java

    satimis


  10. Re: How to fix "JAVA_HOME is set to an invalid directory"

    Please execute once again

    Code:

    export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64

    without the end '/'
    And what you get afterwards out of

    Code:

    $JAVA_HOME/bin/java -version


Bookmarks

Bookmarks

Error: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java 11 openjdk-amd64 bin/java
Posting Permissions

How do I fix Java Home is set to an invalid directory?

To Solve ERROR: JAVA_HOME is set to an invalid directory Error Error Is saying that There is just no need to add bin into PATH variable. You need to set the JAVA_HOME like this. JAVA_HOME=”C:\Program Files\Java\jdk1. 8.0_131″ Just set JAVA_HOME like this and your error will be solved.

How do you fix please set the JAVA_HOME variable in your environment to match the location of your Java installation?

To set JAVA_HOME, do the following: Right click My Computer and select Properties. On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, for example, C:\Program Files\Java\jdk1.

Why JAVA_HOME is not working?

Verify JAVA_HOME Enter the command echo %JAVA_HOME% . This should output the path to your Java installation folder. If it doesn't, your JAVA_HOME variable was not set correctly. Please make sure you're using the correct Java installation folder, or repeat the steps above.

What happens if JAVA_HOME is not set?

If any program that requires a Java runtime fails to find the JAVA_HOME environment variable upon startup, or if the JAVA_HOME environment variable is misconfigured, it will result in some of the following error messages to be displayed: A Java installation exists but JAVA_HOME has been set incorrectly.