Maven: install on mac. Tutorial for brew and the official method.
How to install Maven on mac using brew, tutorial using macOS Monterey - M1
You received your new Apple machine and don't remember how to install Maven? Look no further. In this tutorial, we will describe how to install Maven using Homebrew on macOS. For Windows and Ubuntu users, alternative methods for installation will also be discussed.
Install maven using Homebrew
Homebrew is de facto the package manager for macOS. If you cannot use brew you can look at the alternative installation procedures described in the post.
Here are the few steps required:
Install Homebrew if it is not present yet
Verify that brew is installed in your system.
``` bash brew --version
If Homebrew is installed, this command will display the version number of Homebrew. If Homebrew is not installed, you will see an error message indicating that the command was not found.
Alternatively, you can also check if Homebrew is installed by running the following command:
``` bash
which brewThis command will display the location of the Homebrew executable file if it is installed. If Homebrew is not installed, you will see an error message indicating that the command was not found.
If the command is not found you can install it with the official script from https://brew.sh:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Install maven
If brew is installed in your terminal you can simply execute:
brew mavenMaven will be installed by brew.
Verify your maven installation
When brew confirm the installation you can verify if maven is working correctly.
``` bash % mvn -version Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537) Maven home: /opt/homebrew/Cellar/maven/3.8.4/libexec Java version: 17.0.1, vendor: Homebrew, runtime: /opt/homebrew/Cellar/openjdk/17.0.1/libexec/openjdk.jdk/Contents/Home
In the video we describe how to install _Maven_ using _Homebrew_. In the post you can find alternative methods.
<iframe width="800" height="450" src="https://www.youtube.com/embed/N2aB69xoA3M?si=_h1vBrGLGaztCGSz" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
## Alternative methods
If you can't or you don't want to use _brew.sh_ for the installation of _Maven_ we describe here alternatives methods.
### Official method
The [official maven installation instructions](https://maven.apache.org/install.html) are the following:
1. Have a JDK installation on your system. Set the JAVA_HOME environment variable pointing to your JDK installation or have the java executable on your PATH.
2. Extract the archive in any directory. The archive can be found here: [https://maven.apache.org/download.cgi](https://maven.apache.org/download.cgi)
3. unzip apache-maven-{version}-bin.zip or tar xzvf apache-maven-{version}-bin.tar.gz
4. Add the bin directory of the created directory apache-maven-{version} to the PATH environment variable
### SDKMan
If you are using SDKMan for your Java frameworks you can install [maven](https://sdkman.io/sdks#maven) simply with:
`$ sdk install maven`
You can find more examples about SDKMan in this blog [Java Angular Setup](https://marmo.dev/java-angular-setup)
## Installation on Windows
To install Maven on Windows, you can follow the official installation instructions provided by the Apache Maven project:
- Download the Maven binary archive from https://maven.apache.org/download.cgi
- Extract the archive to the directory where you want Maven installed.
- Add the bin directory of the extracted Maven directory to the PATH environment variable.
- Verify the installation by opening a new command prompt and running the following command:
``` bash
mvn -versionAs an alternative you can use sdkman.io like for MacOs:
- Install sdkman
curl -s "https://get.sdkman.io" | bash- Restart your Command Prompt to activate SDKMAN.
- Run the following command to install Maven:
Installation on Ubuntu
- Open Terminal on your machine
- Run the following command in the Terminal:
``` bash sudo apt-get update sudo apt-get install maven
The apt package manager will handle the installation process for you.
Once the installation is complete, verify the installation by running the following command:
``` bash
mvn -versionUpdating an Existing Maven Installation
Updating Maven on Mac using Homebrew
- Open Terminal.
- Run the following command to update Maven:
brew upgrade mavenUpdating Maven Installation on Ubuntu
To update your Maven installation on Ubuntu, you can use the apt-get package manager to upgrade it.
Here are the steps:
sudo apt-get update
sudo apt-get upgrade mavenThis will upgrade your Maven installation to the latest version available in the Ubuntu repository.