java tutorial: install Java JDK and Maven on Mac
There are two ways to install Java JDK and Maven on mac os:
- Download and install files from the official website
- Install using homebrew package manager
In this tutorial, we will show you how to install Java JDK and Maven on Mac os.
Download and install files from the official website
1. Install Java JDK
1) Download the JDK installation package from the website
https://www.oracle.com/java/technologies/javase-downloads.html
JDK version, currently the most used JDK version is 8, so here I also choose jdk 1.8.
Then according to the operating system used, download the corresponding JDK, I am using mac, so I choose the max os version.
After the download is complete, install it.
2) Open the terminal, type java -version
to check whether the installation is successful, if the version information is output, the installation is successful.
2. Install Maven
1) download maven
http://maven.apache.org/download.cgi
I chose Apache-Maven-3.6.3-bin.tar.gz
2) When the download is complete, double-click the file to unzip or use the tar command to unzip the file
3) Setting environment variables
Assuming the installation package path to /Users/ylspirit/Downloads/apache maven -- 3.6.3
a. Enter vim ~/.bash_profile
on the terminal
b. Enter i
to start editing the file
c. Enter:
export M2_HOME =/Users/ylspirit/Downloads/apache maven -- 3.6.3
export PATH = $PATH: $M2_HOME/bin
d. Click ESC key and enter :wq
to save the file and exit
e. Enter source ~/.bash_profile
in the terminal to make the file effective
4) Type :mvn -v
to check whether the installation is successful. If the version information is output, the installation is successful
➜ ~ mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Install using brew package manager
- Using brew install Java JDK 8
Use Homebrew to install, the version is the latest version of OpenJDK (Java 14):
➜ ~ brew install java
For the many use cases depending on an older version (commonly Java 8), the AdoptOpenJDK project makes it possible with an extra step.
➜ ~ brew tap adoptopenjdk/openjdk
➜ ~ brew cask install adoptopenjdk8
2. Using brew install Java Maven
Use Homebrew to install Maven, the latest version is: Maven 3.6.3
We run the following command to install:
➜ ~ brew install maven
If you want to install other versions of Maven, you can search through the brew search command first:
➜ ~ brew search maven
==> Formulae
maven ✔ maven-shell m[email protected]
maven-completion [email protected] [email protected]
Then install the required version, such as [email protected]:
➜ ~ brew install [email protected]