问题
I'm trying to run a sample app on my android device with the following command :
sudo ionic cordova run android --device
I'm getting this error :
Failed to find 'JAVA_HOME' environment variable. Try setting it manually.
[ERROR] An error occurred while running subprocess cordova.
cordova build android --device exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
I already set the JAVA_HOME environment variable but that doesn't work .
~/Ionic/helloWorld$ echo $JAVA_HOME
/usr/lib/jvm/java-12-openjdk-amd64
Any recommendations ?
回答1:
Your $JAVAHOME
is pointing to the correct location. But the path should have $JAVAHOME/bin
directory and not $JAVAHOME
itself.
JAVA_HOME="/opt/jdk1.12.0"
export JAVA_HOME
PATH="$PATH:$JAVA_HOME/bin"
You should consider using the Oracle Java PPA instead. It usually does more than what a manual installation would do. You don't have to worry about setting up the environment variables either. That's what most people use.
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
Try running java -version and javac -version
to verify that the path is set.
Hope it helps.
回答2:
You have installed java OpenJDK you should install the Java SE. You can find your system-specific JDK here.
Your JAVA_HOME should look like following
/usr/lib/jvm/java-8-oracle (I have java 8 , you can have any version)
回答3:
I have debian 10 and i solve this problem installing openjdk 1.8. And then you have to run:
sudo update-alternatives --config java
sudo update-alternatives --config javac
You don't need to set JAVA_HOME because with update-alternatives java and javac are linked to bin.
来源:https://stackoverflow.com/questions/58356094/failed-to-find-java-home-environment-variable-try-setting-it-manually