Error: JAVA_HOME is not defined correctly - after maven installation

Solution 1:

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.