title: How to fix the error "JAVA_HOME is set to an invalid directory"?
body: <p>I use cordova in my app.</p>
  
  <p>I ran the command </p>
  
  <pre><code>сordova platform add android
  Using cordova-fetch for cordova-android@^8.0.0
  Platform android already added.
  </code></pre>
  
  <p>then cordova build and saw the following error</p>
  
  <pre><code>hacking Java JDK and AndroidSDKversions
  ANDROID_SDK_ROOT=undefined (recommended setting)
  ANDROID_HOME=/usr/lib/android-sdk (DEPRECATED)
  
  ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/default-java/bin
  
  Please set the JAVA_HOME variable in your environment to match the
  location of your Java installation.
  </code></pre>
  
  <p>the readlink-f $(which java) command shows </p>
  
  <pre><code>/usr/lib/jvm/java-8-oracle/jre/bin/java
  </code></pre>
  
  <p>I'm confused and upset, how to solve this problem?</p>
  
  <hr>
  
  <p>I change my .bashrc and add strings</p>
  
  <pre><code>setenv JAVA_HOME /usr/lib/jvm/java-8-oracle/jre/
  setenv PATH $JAVA_HOME/bin:$PATH
  export PATH=$JAVA_HOME/bin:$PATH
  </code></pre>
  
  <p>if I run echo $JAVA_HOME now I seen </p>
  
  <pre><code>/usr/lib/jvm/java-8-oracle
  </code></pre>
  
  <p>I run cordova build I see </p>
  
  <pre><code>Checking Java JDK and Android SDK versions
  ANDROID_SDK_ROOT=undefined (recommended setting)
  ANDROID_HOME=/usr/lib/android-sdk (DEPRECATED)
  Starting a Gradle Daemon (subsequent builds will be faster)
  
  FAILURE: Build failed with an exception.
  Unable to start the daemon process.
  </code></pre>
  
  <p>whats wrong?</p>