I got this error while starting DFS in a new hadoop standalone deployment.
localhost: Error: JAVA_HOME is not set and could not be found.
But JAVA_HOME is set in etc/hadoop/hadoop-env.sh
export JAVA_HOME=${JAVA_HOME}
But java home is set properly using the environment variables.
$ echo $JAVA_HOME
/usr/lib/jvm/java-7-oracle/
Hardcoding the java path in etc/hadoop/hadoop-env.sh solved this issue.
# The java implementation to use.
#export JAVA_HOME=${JAVA_HOME}
export JAVA_HOME=/usr/lib/jvm/java-7-oracle/
Hadoop: hadoop-2.6.4
OS: Ubuntu 16.04 LTS