- Install Maven on your machine.
Maven can be installed manually or by using a package manager tool like brew
(Mac). We’ll first walk through the manual installation process where we
download the archive from the Maven website and add the executable to our PATH.
Here are the steps we’ll follow:
- Download and extract the bin archive.
- Add Maven to our PATH.
- Visit https://maven.apache.org/download.cgi.
- If you’re on Windows, download the apache-maven-3.8.6-bin.zip file.
- If you’re on Mac, download the apache-maven-3.8.6-bin.tar.gz file.
- You can extract the archive to any folder on your machine. We’ll be extracting
it in the
C:/developer
directory on Windows and~/developer
directory on a Mac.
The bin
file in the extracted folder is used to run Maven. If we add this
file’s path to our PATH variable, we’ll be able to use the mvn
command from
anywhere on our machine.
For Windows, run the following command:
setx path "%path%;c:\developer\apache-maven-3.8.6\bin"
For Mac, run the following commands:
export PATH="~/developer/apache-maven-3.8.6/bin:$PATH"
source ~/.zshrc
We can also use Homebrew to install Maven on our machine.
brew install maven
If the above steps worked, you should be able to access the mvn
command from
your command line or terminal. Run the following command to check if it was
installed.
mvn -version
You should get an output like this:
Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: /opt/homebrew/Cellar/maven/3.8.5/libexec
Java version: 17.0.2, vendor: Homebrew, runtime: /opt/homebrew/Cellar/openjdk/17.0.2/libexec/openjdk.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "12.3.1", arch: "aarch64", family: "mac"
This particular machine is running 3.8.5
but yours should list 3.8.6
.
Now that we have a working Maven installation on our machine, we will look into creating projects with Maven and understanding the core concepts in the next lessons.