When I was running "flutter doctor --android-licenses", I struggled to fix the error below,
ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-11-openjdk-amd64
Please set the JAVA_HOME variable in your environment to match the location of your Java installation.
I thought I should post this as a question and provide a response to it, as other Answers to the this question could not help me.
Please see my solution below.
run the below command to choose the java version that you want to use.
sudo update-alternatives --config java
Press the number corresponding to the version of java that you want to use. Example, Press "Enter" to keep the current choice[*], or type selection number: 0
Copy the PATH corresponding to the java version that you chose. In my case since I chose version in Number 0, My PATH is /usr/lib/jvm/java-11-openjdk-amd64/bin/java. But leave out the last part of the PATH,i.e "/bin/java". So now your PATH is /usr/lib/jvm/java-11-openjdk-amd64
run the following command, where PATH value is the value copied from above. export JAVA_HOME=PATH In my case, I will run JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
run this command, copy it as it is. Don't change anything. echo $JAVA_HOME
follow by this command, copy it as it is. Don't change anything. export PATH=$PATH:$JAVA_HOME/bin
run this command, echo $PATH
This will give out the full path to your $JAVA_HOME value.
In my case, this is what I got. /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin :/sbin:/bin:/usr/games:/usr/local/games:/snap/bin :/usr/lib/jvm/java-11-openjdk-amd64/bin
Now you are sorted.
"flutter doctor --android-licenses", ran successfully.