What do I need the JAVA_HOME
, M2
, and M2_HOME
environment variables for if the paths that should go there are already appended to my PATH variable?
Set M2_HOME & PATH Create an environment variable named M2_HOME which refers to directory where maven was untarred/ unzipped. and then add this variable to PATH environment variable. $>export PATH=$M2_HOME/bin:$PATH.
The PATH environment variable is an important security control. It specifies the directories to be searched to find a command. The default systemwide PATH value is specified in the /etc/profile file, and each user normally has a PATH value in the user's $HOME/. profile file.
Why Do You Set A Java Path? The path is the most important environment variable of the Java environment which is used to locate the JDK packages that are used to convert the java source code into the machine-readable binary format. Tools like javac and java can be used by setting the path.
JAVA_HOME and PATH are variables to enable your operating system to find required Java programs and utilities.
JAVA_HOME
should refer to directory where Java that you want to use is installed. This variable is often used by various scripts, so it is recommended to define it. JAVA_HOME
itself should not be added to PATH
. You should add JAVA_HOME/bin
to be able to run commands from this directory without specifying the concrete path.
M2_HOME
is a home of Maven. It is used by script mvn
(or mvn.bat
on Windows).
The home paths (JAVA_HOME
, M2_HOME
) are not mandatory but good to have. One of the advantages is:
It helps you make changes at one place rather than search you way in the PATH
variable when you install next version of Java or Maven. For example JAVA_HOME
environment variable below is a one place I need to change when I upgrade it to Java Development Kit 1.8.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With