How to add Maven to the Path variable?

Viewed 218557

I have downloaded the maven 3.5.0 from here. I have set it in the path:

C:\apache-maven-3.5.0

Then i treid to add it to the path of Windows 7 as below:

  1. Right click on my computer

  2. Properties

  3. Advanced System Setting

  4. Environment Variable

  5. New user variable and added Maven_Home with value C:\apache-maven-3.5.0

  6. Add it to path variable with: %Maven_Home%\bin

  7. Open cmd and ask for mvn -version in desktop

Result:

It does not recognize maven

9 Answers

In windows:

Download the latest version of Maven from the http://maven.apache.org/ and Navigate to Use --> Download --> Download the Binary zip archive.

1) After the download, unzip the folder and copy it to the folder. (Lets say i have copied to c:\program files\apache-maven-3.52.

2) Setting the path of Maven in environment Variables: Search the Environment Variable --> Edit the System Environment variables--> Navigate to Advanced tab --> Environment Variables

i) MAVEN_HOME : Click New --> Variable Name : MAVEN_HOME , Variable Value: C:\Program Files\apache-maven-3.5.2

ii) M2_HOME : Click New --> Variable Name : M2_HOME , Variable Value: C:\Program Files\apache-maven-3.5.2

iii) Edit the 'Path' Environment Variable --> %M2_HOME%\bin

Testing whether Maven is installed: mvn -version

References:- http://www.baeldung.com/install-maven-on-windows-linux-mac

NOTE : In point iii don't forget to put semicolon(;) before and after.

  1. Open command console
  2. copy this set PATH="c:\program files\apache-maven-3.x.y\bin";%PATH%
  3. cahnge the path accordingly
  4. click enter

it's all set and now check mvn -version

I had the same problem and fixed the issue by:

  • Adding the M2_HOME to the USER VARIABLES
  • Adding the MAVEN_HOME to the USER VARIABLES

  • Adding the BIN folder to the PATH in the SYSTEM VARIABLES

(conform this video: https://www.youtube.com/watch?v=RfCWg5ay5B0)

Then i could run mvn -version in a NEW command terminal.

Adding

  1. MAVEN_HOME variable (C:\Program Files\apache-maven-3.5.2) and M2_HOME variable (C:\Program Files\apache-maven-3.5.2\bin).
  2. Add %MAVEN_HOME%\bin to the path in system variables . Then mvn -version in command prompt.

Make sure you download the Binary zip file from https://maven.apache.org/download.cgi. Then it should work fine by adding it to the path variable as mentioned in other answers. I've accidentally downloaded the src.zip file and of course it didn't work. enter image description here

Additionally I would add this information that worked for me

After I opened the Environment Variables and followed these steps:

System variables > path > edit > add this one: C:\apache-maven-3.6.3\bin > ok button.

Also I would send my System variables you may need

System variables

I am using Windows 10

The changes in "System variables" requires system restart to take effect. ( The same for Linux systems also)

Related