Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

StepAction

1) Updating the OS


Code Block
languagebash
sudo apt-get update


2) Download Maven


Code Block
languagebash
sudo wget https://www-us.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P /opt/Download
cd /opt/Download


3) Unzip Maven


Code Block
languagebash
sudo tar xvzf apache-maven-3.6.3-bin.tar.gz -C /opt
sudo chown -R root:root /opt/apache-maven-3.6.3


4) Configuring the Maven environment

To make sure that Maven works properly, you need to set a few environment variables, including JAVA_HOME, M3_HOME, MAVEN_HOME, and PATH.

To make this change, create a file named maven.sh in the /etc/profile.d/ directory.



Code Block
languagebash
sudo vi /etc/profile.d/maven.sh


Code Block
languagebash
title/etc/profile.d/maven.sh
export JAVA_HOME=/usr/lib/jvm/current
export M3_HOME=/opt/apache-maven-3.6.3
export MAVEN_HOME=/opt/apache-maven-3.6.3
export PATH=${M3_HOME}/bin:${PATH}


Code Block
languagebash
sudo chmod +x /etc/profile.d/maven.sh


5) Configuring environment variables




Code Block
languagebash
sudo vi /etc/environment


Code Block
languagebash
title/etc/environnement
linenumberstrue
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/current/bin:/usr/lib/jvm/current/db/bin:/usr/lib/jvm/current/jre/bin:/opt/apache-maven-3.6.3/bin"
J2SDKDIR="/usr/lib/jvm/current"
J2REDIR="/usr/lib/jvm/current/jre"
JAVA_HOME="/usr/lib/jvm/current"
MAVEN_HOME="/opt/apache-maven-3.6.3"


5) Check the installation


Code Block
languagebash
source /etc/profile.d/maven.sh
mvn -version

# Sample answer
Maven home: /opt/apache-maven-3.6.3
Java version: 1.8.0_241, vendor: Oracle Corporation, runtime: /usr/lib/jvm/current/jre
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.0.0-1027-azure", arch: "amd64", family: "unix"


...