title: On "mvn install" command errors with and without "sudo" ("JAVA_HOME" and "--release" flag respectively)
body: <p>I have a project that contains the <code>.pom</code> file. Based on the instruction, I should run the <code>mvn install</code> command first. When I run the command I get the following error:</p>
  <pre><code>Caused by: org.apache.maven.plugin.MojoExecutionException: Fatal error compiling   
  
  Caused by: org.codehaus.plexus.compiler.CompilerException: invalid flag: --release
  
  Caused by: java.lang.IllegalArgumentException: invalid flag: --release
  </code></pre>
  <p>But, when I run the command with <code>sudo</code> (<code>sudo mvn install</code>), I get the following error:</p>
  <pre><code>The JAVA_HOME environment variable is not defined correctly
  This environment variable is needed to run this program
  NB: JAVA_HOME should point to a JDK not a JRE
  </code></pre>
  <p>However, the result of <code>mvn -version</code> command is as follows:</p>
  <pre><code>Apache Maven 3.6.0
  Maven home: /usr/share/maven
  Java version: 1.8.0_265, vendor: Private Build, runtime: /usr/lib/jvm/java-8-openjdk-amd64/jre
  Default locale: en_US, platform encoding: UTF-8
  OS name: &quot;linux&quot;, version: &quot;5.4.0-42-generic&quot;, arch: &quot;amd64&quot;, family: &quot;unix&quot;
  </code></pre>
  <p>On the other hand, I've added the followings to <code>~/.bashrc</code> file:</p>
  <pre><code>export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
  export PATH=/usr/share/maven/bin/mvn:$PATH
  export PATH=$JAVA_HOME/bin:$PATH
  </code></pre>
  <p>The result of <code>echo $JAVA_HOME</code> is:</p>
  <pre><code>/usr/lib/jvm/java-8-openjdk-amd64
  </code></pre>
  <p>and the result of <code>java -version</code> is :</p>
  <pre><code>openjdk version &quot;1.8.0_265&quot;
  OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0ubuntu2~18.04-b01)
  OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)
  </code></pre>
  <p>Besides, I've considered many related posts to my issue, such as <a href="https://stackoverflow.com/q/44680125/3768871">post1</a>, <a href="https://stackoverflow.com/q/43496192/3768871">post2</a>, <a href="https://stackoverflow.com/q/44697803/3768871">post3</a>, and <a href="https://stackoverflow.com/q/60086303/3768871">post4</a> (which are about maven in windows, opposite to my Ubuntu OS) or <a href="https://stackoverflow.com/q/47243223/3768871">post5</a> (that I have not the same problem, as I am not on a VM or any problem with <code>mvn -version</code>. However, mvn version command points to JRE, but all environment variables have been set correctly to point to the JDK). But, none of them resolve it.</p>