Skip to content Skip to sidebar Skip to footer

Failed To Find 'java_home' Environment Variable. Try Setting It Manually

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' envir

Solution 1:

Your $JAVA_HOME is pointing to the correct location. But the path should have $JAVA_HOME/bin directory and not $JAVA_HOME 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-getupdate
sudo apt-get install oracle-java8-installer

Try running java -version and javac -version to verify that the path is set.

Hope it helps.

Solution 2:

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.

Solution 3:

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)

Solution 4:

The only way I've gotten it to work is by declaring the variables in the command itself.

Try it like this:

sudo JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 ANDROID_SDK_ROOT=/usr/lib/Android/Sdk/ cordova requirements android --verbose

Solution 5:

Step 1:

You’ve Java SDK 12 version which is not set into JAVA_HOME environment. You can set this using below command:

JAVA_HOME="/opt/jdk1.12.0"export JAVA_HOME
PATH="$PATH:$JAVA_HOME/bin"

Tip: You can search for list of JDK installed on your machine using: cmd + shift + G and type in /Library/Java/JavaVirtualMachines

Step 2:

If you get an error native-run was not found on your PATH then you need to install globally:

npm i -g native-run

Screenshot-1

Step-3:

While running above command if you get permission denied error then run using super admin privilege:

sudo npm i -g native-run

Screenshot-2

Step-4:

Now again when you run sudo ionic cordova run android --device command you may get error regarding gradle. You can fix this using below command in terminal window:

brew install gradle

Tip: It took me around 10 minutes to install gradle (first time user).

Screenshot-3

Step-5:

Now sudo ionic cordova run android --device command should launch you app on android device without any error.

Post a Comment for "Failed To Find 'java_home' Environment Variable. Try Setting It Manually"