4

I am trying to run commands like maven -version,mvn clean install but get the following error:

$ maven -version
bash: maven: command not found

I have all the necessary Environment variables and Paths in place.

CaldeiraG
  • 2,536
  • 7
  • 18
  • 33
Anit Mohanty
  • 41
  • 1
  • 1
  • 3
  • Does it work in maven install directory? Please add your environment variables to your question also. – Aulis Ronkainen Apr 16 '19 at 18:20
  • Its works in the command prompt but not in git bash. My Environment variables are as following. MAVEN_HOME and path directs to Maven installation folder. JAVA_HOME and the path directs to the JAVA installation folder. In the PATH : I have put the path (untill bin folder) for both Maven and jdk. – Anit Mohanty Apr 17 '19 at 10:06
  • Can you please do `echo %PATH%` and `echo $PATH` and paste the results? How long is your PATH? Does the same error appear if you run `mvn -version` in your Maven installation directory on Git Bash? – Aulis Ronkainen Apr 17 '19 at 19:29
  • The result of echo %PATH% : `C:\Windows\system32>echo %PATH% C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Citrix\System32\;C:\Program Files\Citrix\ICAService\;C:\Softwares\apache-maven-3.3.9\bin;C:\Program Files\Java\jdk1.8.0_144\bin;C:\Program Files\Git\cmd;C:\Users\MO3772\AppData\Local\Microsoft\WindowsApps`
    The result of echo $PATH : `$PATH`
    – Anit Mohanty Apr 18 '19 at 08:03
  • 1
    When I do `mvn -version` in maven installation folder in git bash, it does work. – Anit Mohanty Apr 18 '19 at 08:09
  • @AulisRonkainen . I do not how but I can run maven commands now in git bash in all directories. Thanks for your time and help. The only issue is that, I have to run Git Bash " as administrator" to successfully build my code otherwise the `mvn clean install` fails with reason "access is denied" . – Anit Mohanty Apr 18 '19 at 09:16

3 Answers3

1

Set path as below:

export PATH=$PATH:/c/Program\ Files/Java/jdk1.8.0_221/bin:/c/Program\ Files/apache-maven-3.6.1/bin

0

mvn -v or mvn --version.

Command is not recognized

Probably you are in one of the following 2 situations:

You didn't add the Maven to the path (run ECHO %PATH% in cmd to see if you are in this situation).

Go to the environment variables and click on New… and add:

M2_HOME=<your_path>
MAVEN_HOME=%M2_HOME%
MAVEN_BIN=%M2_HOME%\bin

Click on Edit… and add the ;%MAVEN_BIN% at the end of the path You added it to the path, but you didn't open a new command prompt. Open a new command prompt, because the environment variables are not updated automatically.

CyberSkull
  • 1,465
  • 4
  • 17
  • 31
0

I had the exact same problem.

The solution was to reinstall maven and jdk (I used chocolatey so the paths were automaticly deleted and added again) and simply restart the computer.

Good luck to you all <3