Ubuntu – Error: JAVA_HOME is not defined correctly – after maven installation

12.04environment-variablesinstallationjavamaven-3

I installed Java JDK on Ubuntu 12.04 and added Java home to my path at ~/.bashrc:

export PATH=/opt/jdk1.7.0_40/jdk1.7.0_40/bin:$PATH

This looks a little bit strange but it's really my path.

After this I installed maven through:

sudo apt-get install maven

It installed all the needed libraries and now when I run mvn -version, I see:

Error: JAVA_HOME is not defined correctly.  
We cannot execute /opt/jdk1.7.0_40/bin/java

What is wrong with it?

  • How to solve this trouble?

Best Answer

  • You should add these lines to your ~/.pam_environment file instead (create it if it doesn't exist)

    PATH DEFAULT=${PATH}:/opt/jdk1.7.0_40/jdk1.7.0_40/bin
    JAVA_HOME DEFAULT=/opt/jdk1.7.0_40/jdk1.7.0_40
    

    More information (read this)

    Using .bashrc is not recommended at the above link.