Introduction
Apache Maven is a powerful project management tool that is based on POM (project object model). Maven is a tool that can be used for building and managing any Java-based project. Maven contains XML files also referred to as pom.xml which include configuration details, project dependencies, and other data.
This article will show two different ways to install Apache Maven on openSUSE 15.1 and other versions of openSUSE .
I. Install Maven on openSUSE 15.1
-
Installation of Java: Updating the package index:
sudo zypper up
-
Install the OpenJDK package:
sudo zypper install java-11-openjdk-devel
- Verifying the Java installation:
java -version
Output
openjdk version "11.0.13" 2021-10-19
OpenJDK Runtime Environment (build 11.0.13+8-suse-lp152.2.21.2-x8664)
OpenJDK 64-Bit Server VM (build 11.0.13+8-suse-lp152.2.21.2-x8664, mixed mode)
Apache Maven Download
- Download the stable version of Apache Maven and you can download it to the "/tmp" directory, as shown below:
cd /tmp/
sudo wget http://mirrors.advancedhosters.com/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -
The file will be downloaded as a tar.gz file. You can extract files to /opt directory:
sudo tar -xvzf apache-maven-3.6.3-bin.tar.gz -C /opt
-
In order to have control of Maven versions and updates, we will create a symbolic link to Maven that points to the Maven installation directory. Run the below command:
sudo ln -s /opt/apache-maven-3.6.3 /opt/maven
- Move to the root path before setting up the environments for Maven:
cd
Setup the Environment for Maven
You must configure a few environment variables, including JAVA_HOME, M3_HOME, and MAVEN_HOME.
- Create a new file named
maven.sh
inside the/etc/profile.d/
directory.sudo vi /etc/profile.d/maven.sh
-
The configuration below needs to be added to this newly created file:
Save and close the file.export M2_HOME=/opt/maven/
export M2=$M2_HOME/bin
export PATH=$M2:$PATH -
Provide the required privileges to the file using the command below:
sudo chmod +x /etc/profile.d/maven.sh
- Load the environment variables using the
source
command:source /etc/profile.d/maven.sh
Verify the Maven installation
-
Use the command
mvn -version
which will print the Maven version:mvn -version
Output
Apache Maven 3.6.3 (SUSE 3.6.3-lp152.2.31)
Maven home: /usr/share/maven
Java version: 11.0.13, vendor: Oracle Corporation, runtime: /usr/lib64/jvm/java-11-openjdk-11
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "5.3.18-lp152.17-default", arch: "amd64", family: "unix"
Install Apache Maven using Zypper
- An easy and simple way to install maven using Zypper. Update the package index by using the following command,
sudo zypper up
-
Install Maven.
sudo zypper install maven
- Verify the installation by running the
mvn -version
command:mvn -version