Languages

Debian - Warning: JAVA_HOME environment variable is not set. - how to solve it?

7 points
Asked by:
AnnLen
1780

When I run mvn install commnad to build my java project on Debian 9 I get this warning:

Warning: JAVA_HOME environment variable is not set.

This warning causes that my java build fails.

How can I fix it?

1 answers
7 points
Answered by:
AnnLen
1780

You need to ensure you have installed correct version of java, I suggest jdk 8.

1. To check java version, execute command:

java -version

2. If we install open JDK, the default location should be:

/usr/lib/jvm/java-8-openjdk-amd64

3. Open /etc/profile

vim /etc/profile

4. Set JAVA_HOME path and add java bin directory to the PATH variable. In order to do that, we need to add below 2 lines to /etc/profile

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH=$PATH:$JAVA_HOME/bin

5. Logout from putty, login again 

6. Ensure we have java on our PATH by executing below commnad:

echo $PATH

7. Ensure we have $JAVA_HOME env variable:

echo $JAVA_HOME

8. Run mvn install in your java project and warning should be gone.

0 comments Add comment
Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.