Apache Maven is one of the most popular build management tools used for Java projects. It is based on a POM (project object model) and used for project build, dependency, and documentation. It is very useful for Java developers to manage an entire project’s build process, including storing documents, reporting, and more. Apache Maven uses an XML file to store information about projects, configurations, and dependencies.
In this post, we will show you how to install Apache Maven on Arch Linux.
Step 1 – Configure Repository
By default, the default repository is outdated in Arch Linux, so you will need to modify the default mirror list. You can do it by editing the mirrorlist configuration file:
nano /etc/pacman.d/mirrorlist
Remove all lines and add the following lines:
## Score: 0.7, United States Server = http://mirror.us.leaseweb.net/archlinux/$repo/os/$arch ## Score: 0.8, United States Server = http://lug.mtu.edu/archlinux/$repo/os/$arch Server = http://mirror.nl.leaseweb.net/archlinux/$repo/os/$arch ## Score: 0.9, United Kingdom Server = http://mirror.bytemark.co.uk/archlinux/$repo/os/$arch ## Score: 1.5, United Kingdom Server = http://mirrors.manchester.m247.com/arch-linux/$repo/os/$arch Server = http://archlinux.dcc.fc.up.pt/$repo/os/$arch ## Score: 6.6, United States Server = http://mirror.cs.pitt.edu/archlinux/$repo/os/$arch ## Score: 6.7, United States Server = http://mirrors.acm.wpi.edu/archlinux/$repo/os/$arch ## Score: 6.8, United States Server = http://ftp.osuosl.org/pub/archlinux/$repo/os/$arch ## Score: 7.1, India Server = http://mirror.cse.iitk.ac.in/archlinux/$repo/os/$arch ## Score: 10.1, United States Server = http://mirrors.xmission.com/archlinux/$repo/os/$arch
Save and close the file, then update all the package indexes with the following command:
pacman -Syu
Step 2 – Install Java OpenJDK
Apache Maven is a Java-based application, so you will need to install Java on your system.
You can install Java with the following command:
pacman -S jre-openjdk
Once Java is installed, verify the Java version using the following command:
java --version
You should see the following output:
openjdk 18.0.2 2022-07-19 OpenJDK Runtime Environment (build 18.0.2+0) OpenJDK 64-Bit Server VM (build 18.0.2+0, mixed mode)
Step 3 – Install Apache Maven from Source
If you want to install the latest version of Apache Maven, then you will need to install it from the source.
First, go to the Apache Maven download page and download the latest version using the following command:
wget https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz
Once the download is completed, create a directory for Apache Maven and extract the downloaded file inside the Apache Maven directory:
mkdir /usr/local/maven tar xzf apache-maven-3.8.6-bin.tar.gz -C /usr/local/maven/ --strip-components=1
Next, create an environment variable for Apache Maven using the following command:
echo export 'PATH=$PATH:/usr/local/maven/bin/' > /etc/profile.d/maven.sh echo 'export JAVA_HOME=/usr/lib/jvm/java-18-openjdk/' >> /etc/profile.d/maven.sh
Next, set execution permissions on the created file with the following line:
chmod +x /etc/profile.d/maven.sh
Next, activate the Apache Maven environment variable with the following command:
source /etc/profile.d/maven.sh
Next, verify the Apache Maven version using the following command:
mvn --version
You will get the following output:
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63) Maven home: /usr/local/maven Java version: 18.0.2, vendor: N/A, runtime: /usr/lib/jvm/java-18-openjdk Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "5.8.14-arch1-1", arch: "amd64", family: "unix"
Step 4 – Install Apache Maven from the Repository
The simple and easiest way to install Apache Maven is to install it from the Arch Linux default repository.
Run the following command to install Apache Maven:
pacman -S maven
Once the Apache Maven is installed, you can verify the Apache Maven version using the following command:
mvn --version
You should get the following output:
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63) Maven home: /opt/maven Java version: 18.0.2, vendor: N/A, runtime: /usr/lib/jvm/java-18-openjdk Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "5.8.14-arch1-1", arch: "amd64", family: "unix"
Conclusion
In this post, we explained two methods to install Apache Maven on Arch Linux. You can now use Apache Maven in your development environment and start managing Java-based projects. Try to install Apache Maven on dedicated hosting from Atlantic.Net!