641

I'm trying to install maven through the terminal by following these instructions.

So far I got this:

export M2_HOME=/user/apple/apache-maven-3.0.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
export JAVA_HOME=/usr/java/jdk1.6.0_22

Where do you go to find this?

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Edgardo Roldan
  • 6,522
  • 3
  • 16
  • 9
  • 2
    What _is it_ that you are trying to find? With the environment variables the way you have listed them you _should be_ able to invoke the `mvn` executable from your terminal window. – Sri Sankaran Jan 12 '12 at 02:47
  • If, as in my case, you are trying to downgrade from Maven 3 back to Maven 2, see this excellent blog: http://blog.frau-klein.org/2011/04/how-to-downgrade-maven-from-3-x-to-2-x-on-mac-os/ – Jeff Jan 02 '14 at 15:46
  • 2
    Edgardo I think you should uncheck the checked answer if you can... – jcollum Sep 09 '16 at 19:23
  • I think that as of 2020 the answer using Homebrew should be the preferred one, what do you think? – Matthieu Wipliez Jun 30 '20 at 14:39
  • Where do you go to find what? The answers explain how to install maven, but what is the question actually asking? – user985366 Jan 22 '23 at 17:44

26 Answers26

2107

Alternatively, I recommend installing Homebrew for these kinds of utilities.

Then you just install Maven using:

brew install maven

PS: If you got a 404 error, try doing a brew update just before

Yves M.
  • 29,855
  • 23
  • 108
  • 144
brasskazoo
  • 76,030
  • 23
  • 64
  • 76
  • 170
    In OS X 10.9 Mavericks, as there is no maven installed (at least in the beta) this is the right answer. – Nacho L. Aug 14 '13 at 13:19
  • 10
    It's one answer, but not exclusively the "right" one. Downloading the Maven binary zip from the Maven website is quicker and easier IMO. – RCross Sep 25 '13 at 09:53
  • 16
    On OS X 10.9 you should use `brew install maven30` since maven 3.1.1 seems to be buggy. – tadeuzagallo Oct 24 '13 at 14:11
  • 18
    ```brew install homebrew/versions/maven30```did for me. Thanks @TadeuZagallo !! – fmquaglia Nov 19 '13 at 00:12
  • 17
    No need to use `brew install maven30` anymore as the most current version 3.2.1 is pretty fast and seems to not have the bugs that 3.1.1 had. – Michael Hogenson May 29 '14 at 19:01
  • 1
    Install brew before if you don't have it yet, have a look at the last part of this page http://brew.sh/ – Jibeex Sep 10 '14 at 16:11
  • 2
    If you are having environment variable issues with maven 3 on OSX 10.9.4 check out this [blog post](http://digitalsanctum.com/2010/12/31/maven-3-homebrew-install/). – craastad Sep 14 '14 at 16:41
  • 2
    Why would you install brew in this case when installing maven by hand is both faster and easier? I don't want to be tied to how fast Brew updates its sources. – MiB Nov 22 '14 at 03:52
  • 3
    @MiB Fair enough; I use brew for multiple tools & applications, so it makes sense for me. I also mostly don't require the bleeding edge, so brew is 'good enough' for me. – brasskazoo Nov 23 '14 at 23:17
  • 5
    If you got a 404 error, try doing a `brew update` just before ;) – Yves M. Feb 13 '15 at 20:35
  • 1
    In case you have more thank one version remember to run `sudo port select --set maven maven3` to activate it after running the command on this answer – JordanBelf Feb 27 '15 at 15:20
  • 1
    The issue with this approach is having multiple versions of maven installed at the same time (some legacy projects stuck on 2.2.1). Brew allows you to switch versions pretty easily, but downgrading no so much (if you run brew cleanup) – Michael May 28 '15 at 16:41
  • 1
    brew install maven works like a charm in OSX ELcapitan – ashish Apr 21 '16 at 19:50
  • 1
    But if you use the homebrew, the open jdk will be installed, if you use the JDK(Oracle) is better try install manually. – LandiLeite Jul 20 '20 at 15:51
  • 1
    Anyone know for sure where the default repo (as in MAVEN_HOME) would be on a Mac? Seems the "settings.xml" should be place here: /usr/local/Cellar/maven//libexec/conf according to: https://stackoverflow.com/a/24395072/335867 Would it still be "~./m2" like one would typically make it when installing manually? As in: "/Users/USERNAME/.m2" – bcmoney Aug 26 '20 at 16:16
  • IMO this is the best way to install maven on MacOS Catalina. Following instructions on the maven website installs it in bash and macOS uses zsh. – praty Mar 19 '21 at 22:12
250

Disclaimer: Here is a complete answer taking the last version of OS X (10.9 AKA Mavericks) into account. I am aware that everything I compiled in this answer is already present in the page, but having it clearly in one answer makes it a lot clearer.

First of all, with previous versions of OS X, Maven is installed by default. If Java is missing running you@host:~ $ java in a terminal will prompt you for the Java installation.

With Mac OS X 10.9 (Mavericks), Maven is not installed by default anymore. Different options are then possible:

  • Using Homebrew:
    • you@host:~$ brew install maven will install latest Maven (3.5.2 on 02/01/2018)
    • you@host:~$ brew install maven30 will install Maven 3.0 if needed
  • Using Macports: (I did not test this)
    • you@host:~$ sudo port install maven will install latest Maven (?)
    • or:
    • you@host:~$ sudo port install maven3 will Install Maven 3.0
    • you@host:~$ sudo port select --set maven maven3 selects that version of Maven
  • Installing by hand:
    • Download Maven from its homepage
    • Follow the installation instructions:
      1. Extract the distribution archive, i.e.apache-maven-3.3.9-bin.tar.gz to the directory you wish to install Maven 3.3.9. The subdirectory apache-maven-3.3.9 will be created from the archive.
      2. Optional: Add the MAVEN_OPTS environment variable to specify JVM properties, e.g. export MAVEN_OPTS="-Xms256m -Xmx512m". This environment variable can be used to supply extra options to Maven.
      3. Make sure that JAVA_HOME is set to the location of your JDK, e.g. export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) and that $JAVA_HOME/bin is in your PATH environment variable (although that might not be necessary with the latest Mac OS X versions and the Oracle JDK).
      4. Add extracted apache-maven-3.3.9/bin to your $PATH
      5. Run mvn --version to verify that it is correctly installed.
rexford
  • 5,192
  • 5
  • 27
  • 40
snooze92
  • 4,178
  • 2
  • 29
  • 38
  • 6
    `sudo port install maven3` installs Maven 3.0.5. – njudge Mar 07 '14 at 18:24
  • 3
    When installing by hand, rather than dig around trying to find `JAVA_HOME`, consider using `export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)` (cf [this answer](http://stackoverflow.com/a/6588410/27358)). Also (at least on Mavericks and Yosemite with the Oracle JDK 1.8) you shouldn't need `$JAVA_HOME/bin` in your path as everything's symlinked from `/usr/bin`. – David Moles Jan 09 '15 at 21:55
  • You're right about the better way to define `JAVA_HOME`! I didn't know about the symlinks but I edited my answer to include your remarks. Thanks – snooze92 Jan 12 '15 at 07:20
  • 1
    better to add the `export` instructions to `~/.bash_profile` to make it available in all sessions, see [this post](https://stackoverflow.com/questions/21028872/mvn-command-not-found-in-osx-mavrerick/21030998#21030998) for details – Mzq Jun 25 '15 at 15:22
  • Better than what, @Miranda ? I did not specify where to do the `export`s in the _"installing by hand"_ option because I reckon people choosing the manual installation know best where they want to do these exports. This is quite specific to each person and each system, I feel. – snooze92 Jul 02 '15 at 08:42
  • I'm not an expert on this, but it appears that as of maven-3.3.x, M2_HOME environment variable is no longer needed (and may even cause trouble). – fearless_fool Jan 20 '17 at 06:02
  • @fearless_fool You're right; I've updated the manual section of the answer. – snooze92 Jan 20 '17 at 12:35
226

OS X prior to Mavericks (10.9) actually comes with Maven 3 built in.

If you're on OS X Lion, you won't have java installed by default. Run java by itself and it'll prompt you to install it.

Assuming qualifications are met, run mvn -version and see some output like this:

Apache Maven 3.0.3 (r1075438; 2011-02-28 12:31:09-0500)
Maven home: /usr/share/maven
Java version: 1.6.0_29, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.7.2", arch: "x86_64", family: "mac"
Harry B
  • 2,864
  • 1
  • 24
  • 44
Michael
  • 6,141
  • 2
  • 20
  • 21
  • Does Lion come with 3.0.3? if I recall, Snow Leopard only has 2.2.x. – yorkw Jan 11 '12 at 22:03
  • 1
    If you for some reason need maven 2 on lion, you need to download it, set your M2_HOME, and then you need to make sure that wherever you installed it comes before /usr/bin in your path, or swap the /usr/bin/mvn out for a symlink to yours. I know a lot of people work on stuff with maven 2 still, myself included. – Michael Jan 16 '12 at 15:45
  • 3
    Just fyi, Mountain Lion comes with 3.0.3 as well. – Michael Oct 23 '12 at 20:39
  • And here is a link on how to update to the latest version : http://www.myjeeva.com/2011/04/how-to-do-maven-upgrade-in-mac-os-x/ – skiabox Mar 03 '13 at 21:48
  • 415
    Update, with OSX 10.9 Maverick, Maven is not installed by default any more. – Jerry Tian Oct 24 '13 at 08:05
  • With 10.9 Maverick, maven 3.0.4 is installed once you install java. They don't install java by default (mountain lion did this too). – Michael Oct 24 '13 at 16:59
  • 15
    @Michael I installed Java on Maverick, but it didn't install Maven for me. – Swapnil Oct 25 '13 at 13:43
  • True, Maven is not on OSX and does not install with the command line tools or with a jdk download from sun. However the downloads from apache are trivial to install. – David Williams Oct 27 '13 at 16:05
  • You might also need to update this link after installing jdk 1.7 ` sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK` or whereever your java 1.7 is installed. Also export JAVA_HOME as `export JAVA_HOME=$(/usr/libexec/java_home)` – David Williams Oct 27 '13 at 16:42
  • @Swapnil - xcode command line tools provides it then. My /usr/bin/mvn is maven 3.0.4 on Mavericks. – Michael Oct 28 '13 at 02:34
  • 6
    Yosemite does not include maven as part of the install, with java or with xcode command line tools. – Michael Nov 09 '14 at 20:06
  • 1
    after installing by 'brew install maven' I got maven worked only after additionally setting up M2_HOME, M2 and adding them to PATH – Yauhen Jul 08 '15 at 07:14
  • I simply did "brew install maven" on El Capitan (hint: requires HomeBrew to be installed on machine) – fiorentinoing Jul 15 '16 at 18:57
  • This worked for me. Thanks. You are right if somehow downloading dependency is interrupted then deleting .m2 file is the fix, if pom file is correctly configured. – Emy Jan 20 '17 at 01:03
90

When I upgraded recently to OS X Mavericks and my maven builds start failing. So I needed to install maven again as it doesn't come built in. Then I tried with the command:

brew install maven 

it works, but it installs the version 3.1.1 of maven which causes some problems for a few users like (https://cwiki.apache.org/confluence/display/MAVEN/AetherClassNotFound). So if you're running into the same issue you will probably want to install the earlier Maven version, the 3.0.5. To do that with Homebrew, you have to execute the following command:

brew install https://raw.github.com/Homebrew/homebrew-versions/master/maven30.rb

That's it, it will then use a different Homebrew's formulae which will give you the maven 3.0.5 instead.

arghtype
  • 4,376
  • 11
  • 45
  • 60
Alécio Carvalho
  • 13,481
  • 5
  • 68
  • 74
  • The raw file is currently 503-ing sporadically. When it did work, I saved it down to a local file. – NRitH Oct 29 '13 at 20:58
  • 1
    Had to manually edit the brew file to avoid a 404. 'brew edit maven'. I hard coded in one of the mirrors for the 'url' and also had to change the 'sha' checksum. url 'http://apache.mesi.com.ar/maven/maven-3/3.0.4/binaries/apache-maven-3.0.4-bin.tar.gz' sha1 'aecc0d3d67732939c0056d4a0d8510483ee1167e' – Derek Oct 30 '13 at 09:14
  • Also be sure to `brew update` to get the latest before doing `brew install maven`, if you want brew to install maven 3.1.1+. – Gary S. Weaver Dec 05 '13 at 04:18
  • 2
    `brew install maven30` – timomeinen Jun 30 '14 at 12:52
  • 1
    I just used `brew install maven` and it installed 3.0.5. Here's what prints when I do `mvn -version`: `mvn -version Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 05:51:28-0800) Maven home: /usr/local/Cellar/maven/3.0.5/libexec Java version: 1.7.0_45, vendor: Oracle Corporation Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "10.9.3", arch: "x86_64", family: "mac"` – Azurespot Jul 05 '14 at 07:04
  • Did you do `brew update` recently? I just tried `brew install maven` on a laptop with Mavericks that had never had Maven installed, and got Apache Maven 3.3.3. – snooze92 Jun 27 '15 at 12:12
50

macOS Sierra onwards

brew install maven

Saorikido
  • 2,173
  • 2
  • 26
  • 37
  • 4
    While this code snippet may solve the question, [including an explanation](//meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, this reduces the readability of both the code and the explanations! – kayess May 05 '17 at 07:42
  • 1
    If you're getting 'brew command not found' you need to install brew first. That is link to off website https://brew.sh/ That is command to install `/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"` – 3akat May 16 '17 at 05:27
46

To install Maven on OS X, go to the Apache Maven website and download the binary zip file.

You can then shift the apache-maven-3.0.5 folder in your Downloads folder to wherever you want to keep Maven; however as the rest of the process involves the command line, I recommend you do everything from there.

At the command line, you would run something like:

mv ~/Downloads/apache-maven-3.0.5 ~/Development/

This is just my personal preference - to have a "Development" directory in my home directory. You can choose something else if you wish.

Next, edit ~/.profile in the editor of your choice, and add the following:

export M2_HOME="/Users/johndoe/Development/apache-maven-3.0.5"
export PATH=${PATH}:${M2_HOME}/bin

The first line is important to Maven (and must be a full explcit path); the second line is important to the shell, in order to run the "mvn" binary. If you have a variation of that second line already in .profile, then simply add ${M2_HOME}/bin to the end of it.

Now open a second terminal window and run

mvn -version

which should give output like...

Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 13:51:28+0000)
Maven home: /Users/johndoe/Development/apache-maven-3.0.5
Java version: 1.7.0_40, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9", arch: "x86_64", family: "mac"

Couple of things to note:

  1. If you've installed the Oracle JDK 1.7, then you may find Maven reports JDK 1.6 in the above output. To solve this, add the following to your ~/.profile:

    export JAVA_HOME=$(/usr/libexec/java_home)

  2. As some have pointed out, Maven has historically been supplied either with OS X itself, or with the optional Command Line Tools for XCode. This may cease to be the case for future versions of OS X, and in fact OS X Mavericks does not include Maven. Personal opinion: This could be because they are still in beta, or it could be that Apple have taken a look at the latest Thoughtworks Technology Radar, and spotted that Maven has been moved to "Hold".

RCross
  • 4,919
  • 4
  • 44
  • 42
  • 3
    As of the day after Mavericks was released, it no longer comes with Maven. your instructions here helped. – Bryce Fischer Oct 23 '13 at 15:41
  • I think I've followed these instructions exactly, even the ~/Development. But apache-maven-3.0.5 has no subdirectory "bin". – garyp Aug 07 '14 at 02:11
  • Whoops, I downloaded the source distribution, not the bin. Sorry for the noise. – garyp Aug 07 '14 at 02:16
  • What is the equivalent of .profile or .bash_profile for MAC OS Sierra(10.12.4)? I am trying to install maven and I don't have a .profile or a .bash_profile in my home account... – Crenguta S May 05 '17 at 07:23
  • @CrengutaS It's ~/.profile, but the file doesn't exist by default; you have to create it. For an explanation as to why there's no .bash_profile, see the first answer to https://apple.stackexchange.com/questions/119711/why-doesnt-mac-os-x-source-bashrc – RCross May 09 '18 at 10:59
40

If using MacPorts on OS X 10.9 Mavericks, you can simply do:

sudo port install maven3
sudo port select --set maven maven3
Oliver
  • 3,815
  • 8
  • 35
  • 63
Marc Smith
  • 1,111
  • 10
  • 18
26

A simple approach to install Maven.

  1. Open Terminal

Finder -> Go -> Utilities -> Terminal

  1. Install Homebrew using the below command

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  1. After that install maven

brew install maven

Saurabh Padwekar
  • 3,888
  • 1
  • 31
  • 37
25

Just a brief addition; if you want to install a specific version on MacOS using Homebrew 1.5.2, you can install it the following way:

  1. brew update
  2. brew search maven

This will give you maven versions available in homebrew

  1. brew install maven@3.3

[If you want to install maven 3.3.]

zafar142003
  • 2,081
  • 2
  • 24
  • 31
17

Two Method

  • (use homebrew) Auto install:
    • Command:
      • brew install maven
    • Pros and cons
      • Pros: easy
      • Cons: (probably) not latest version
  • Manually install (for latest version):
    • Pros and cons
      • Pros: use your expected any (or latest) version
      • Cons: need self to do it
    • Steps
      • download latest binary (apache-maven-3.6.3-bin.zip) version from Maven offical download
      • uncompress it (apache-maven-3.6.3-bin.zip) and added maven path into environment variable PATH
        • normally is edit and add:
          • export PATH=/path_to_your_maven/apache-maven-3.6.3/bin:$PATH
        • into your startup script( ~/.bashrc or ~/.zshrc etc.)

Extra Note

how to take effect immediately and check installed correctly?

A:

source ~/.bashrc
echo $PATH
which mvn
mvn --version

here output:

➜  bin pwd
/Users/crifan/dev/dev_tool/java/maven/apache-maven-3.6.3/bin
➜  bin ll
total 64
-rw-r--r--@ 1 crifan  staff   228B 11  7 12:32 m2.conf
-rwxr-xr-x@ 1 crifan  staff   5.6K 11  7 12:32 mvn
-rw-r--r--@ 1 crifan  staff   6.2K 11  7 12:32 mvn.cmd
-rwxr-xr-x@ 1 crifan  staff   1.5K 11  7 12:32 mvnDebug
-rw-r--r--@ 1 crifan  staff   1.6K 11  7 12:32 mvnDebug.cmd
-rwxr-xr-x@ 1 crifan  staff   1.5K 11  7 12:32 mvnyjp
➜  bin vi ~/.bashrc
➜  bin source ~/.bashrc
➜  ~ echo $PATH
/Users/crifan/dev/dev_tool/java/maven/apache-maven-3.6.3/bin:xxx
➜  bin which mvn
/Users/crifan/dev/dev_tool/java/maven/apache-maven-3.6.3/bin/mvn
➜  bin mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Users/crifan/dev/dev_tool/java/maven/apache-maven-3.6.3
Java version: 1.8.0_112, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"

for full detail please refer my (Chinese) post: 【已解决】Mac中安装Gradle

crifan
  • 12,947
  • 1
  • 71
  • 56
12

This command brew install maven30 didn't work for me. Was complaining about a missing FORMULA. But the following command did work. I've got maven-3.0.5 installed.

brew install homebrew/versions/maven30

This is for Mac OS X 10.9 aka Mavericks.

DarkAjax
  • 15,955
  • 11
  • 53
  • 65
edufinn
  • 2,369
  • 1
  • 21
  • 19
  • 1
    This is the best answer for the ones having issues with the very buggy maven 3.1.1 that `brew install maven` is installing now. – Nacho L. Nov 09 '13 at 10:29
  • @ShajeelAfzal You need to install [Homebrew](http://brew.sh). Can be done with the following command: `/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"` – edufinn Feb 02 '16 at 07:59
  • `brew install homebrew/versions/maven32` works for me on Sierra – Tobi Feb 22 '17 at 16:27
  • Now I would recommend to install latest Maven with `brew install maven`. – edufinn Feb 28 '17 at 15:41
10

If you don't want to install Homebrew only for install Maven you could simply do this:

  1. Download the binary Maven and extract the zip

  2. Launch the Terminal and type this command:

    sudo ln -s /path_to_maven_folder/bin/mvn /usr/bin/mvn

You can find more details on this post.

Fred K
  • 13,249
  • 14
  • 78
  • 103
  • 1
    I get `ln: /usr/bin/mvn: Operation not permitted` response, i think i need to follow this: http://stackoverflow.com/a/32661637/1773155 to resolve the problem. – Shajeel Afzal Jan 29 '16 at 12:02
  • in El-Capitan, I found that it needed to go into /usr/local/bin/mvn. Seems the cleaner way than the above referenced stackvoerflow link – eric Jun 29 '17 at 19:04
9
  1. Open terminal
  2. Just use brew command to install maven
brew install maven
  1. After the download and install finished. Check for the maven version
mvn -version

Here you go !!! Now you have successfully installed maven on your mac os.

Ananta Chandra Das
  • 1,865
  • 2
  • 14
  • 18
9

If you have tried brew install maven and were greeted with missing gcc compiler and some other dependencies, an easier approach is to install sdkman and then run

sdk install maven

(or refer to the latest documentation for the right command)

sdkman is probably over-qualified for the job, but if you deal with multiple versions of SDKs, it's a pretty nice tool to have in general.

Credits to Ammar for the excellent tip

Niks
  • 4,802
  • 4
  • 36
  • 55
7
brew install maven31 (if you have homebrew)
bjliu
  • 192
  • 1
  • 2
  • 14
6

for the ones that just migrated to mavericks - I used the *-ux solution;

  1. download maven from apache maven site
  2. put in /opt
  3. modified .bash_profile and added:

    alias mvn='/opt/apache-maven-3.1.1/bin/mvn'
    export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home
    
laalto
  • 150,114
  • 66
  • 286
  • 303
guest
  • 77
  • 1
  • 1
3

Open a TERMINAL window and check if you have it already installed.

Type:

$ mvn –version

And you should see:

Apache Maven 3.0.2 (r1056850; 2011-01-09 01:58:10+0100)
Java version: 1.6.0_24, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: “mac os x”, version: “10.6.7″, arch: “x86_64″, family: “mac”

If you don't have Maven installed already, then here is how to download and install maven, and configure environment variables on Mac OS X:

http://bitbybitblog.com/install-maven-mac/

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
user1187534
  • 789
  • 1
  • 8
  • 12
2

On Maverick, run in the terminal xcode-select --install to install the Command Line Tools.

Ilya Saunkin
  • 18,934
  • 9
  • 36
  • 50
  • If you attempt to install Homebrew this will happen automatically if you don't already have the tools installed. – JavaCoderEx Jan 07 '14 at 17:01
2

You can use Maven Version Manager through which you can use multiple version of Maven per directory base.

Installation

Using Homebrew brew install mvnvm

Without Homebrew mkdir -p ~/bin && curl -s https://bitbucket.org/mjensen/mvnvm/raw/master/mvn > ~/bin/mvn && chmod 0755 ~/bin/mvn and add ~/bin to path.

Usage

Default Version

To set default maven version set the environment variable DEFAULT_MVN_VERSION to the maven version to be used by default.

Maven version for the folder

Create a file named mvnvm.properties in the folder and configure the maven version as follows

mvn_version=<maven version>

seenukarthi
  • 8,241
  • 10
  • 47
  • 68
2

Two ways to install Maven

Before installing maven check mvn -version to make sure maven is not install in system

Method 1:

brew install maven

Method 2:

  1. go to https://maven.apache.org/download.cgi
  2. Select any of Binary link
  3. Unzip the link
  4. Move to application folder
  5. Update .bash profile with exports
  6. run mvn -version
CuriosCoder
  • 91
  • 1
  • 9
1

This worked for me:

$ vim .bash_profile

export JAVA_HOME=$(/usr/libexec/java_home)

$ source .bash_profile

credit: http://www.mkyong.com/java/maven-java_home-is-not-defined-correctly-on-mac-osx/

Andrew Betts
  • 338
  • 4
  • 6
1
% sudo port selfupdate; 
% sudo port upgrade outdated;
% sudo port install maven3;
% sudo port select --set maven maven3;

— add following to .zshenv -- start using zsh if you dont —
set -a
[[ -d /opt/local/share/java/maven3 ]] &&
    M3_HOME=/opt/local/share/java/maven3 &&
    M2_HOME=/opt/local/share/java/maven3 &&
    MAVEN_OPTS="-Xmx1024m" &&
    M2=${M2_HOME}/bin
set +a
yuzhewo
  • 11
  • 2
1

You can install maven using homebrew. The command is $ brew install maven

Shivam Kohli
  • 449
  • 4
  • 6
1

After installing maven using brew or manually, using macOS Catalina and using the terminal or iTerm to operate maven you will need to grant access to the apps to access user files.

System Preferences -> Privacy (button) -> Full Disk Access

And then add terminal or iTerm to that list.

You will also need to restart your application e.g. terminal or iTerm after giving them full disk access.

dirbacke
  • 2,861
  • 21
  • 25
0

For those who wanna use maven2 in Mavericks, type:

brew tap homebrew/versions

brew install maven2

If you have already installed maven3, backup 3 links (mvn, m2.conf, mvnDebug) in /usr/local/bin first:

mkdir bak

mv m* bak/

then reinstall:

brew uninstall maven2(only when conflicted)

brew install maven2

Anderson
  • 2,496
  • 1
  • 27
  • 41
0

This worked for me. Its simpler and cleaner. Open Mac terminal and type:

export MAVEN_HOME=~/apache-maven-3.8.1
export PATH=$PATH:$MAVEN_HOME/bin

Now when you type

mvn -version

You get an output:

Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /Users/nisha/apache-maven-3.8.1
Java version: 16.0.1, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-16.0.1.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "11.4", arch: "x86_64", family: "Mac"

** Edited to add:

When you close the terminal and open again, you will get mvn: command not found and you will have to run the command again.

Refer this post for a permanent installation

ngrashia
  • 9,869
  • 5
  • 43
  • 58