Maven on Java 21 and Devuan 5 (Debian 12): Install manually

Table of contents

Summary Summary

Apache (opens in a new tab) Maven (opens in a new tab) is a popular open source software to build and manage projects of Java (opens in a new tab) (and also other programming languages), licensed under Apache-2.0 (opens in a new tab).

With Devuan (opens in a new tab) 5 Daedalus (opens in a new tab) based on Debian (opens in a new tab) 12 bookworm (opens in a new tab), it is easy to use it thanks to their packages management (opens in a new tab). However, it is not always the latest. Actually, Maven Debian 12 offers is currently 3.8 (opens in a new tab) instead of 3.9 (opens in a new tab). Well, is it a big problem ? Probably, no.

In my previous post, I installed OpenJDK (opens in a new tab) 21 (opens in a new tab), the latest, manually on Devuan 5. Here, I will show how to install Maven manually, too. Of course, it is easier to run apt install maven 🫣

Environment Environment

  • OS: Devuan 5 Daedalus
    • based on Debian 12
  • App Engine: OpenJDK 21
  • Project Build and Management: Apache Maven 3.9.5 (opens in a new tab)

Tutorial Tutorial

Suppose that your PATH includes Java 21 bin which appears before those of other Java versions such as 17 (the previous LTS).

Get Apache Maven package Get Apache Maven package

Visit: https://maven.apache.org/download.cgi (opens in a new tab)

Get the binary with the command line, for example:

console
$ curl -LO https://dlcdn.apache.org/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5-bin.tar.gz

You can verify the download by comparing the checksums between the server and the local. Use the command lines below, for example:

console
$ echo "$(curl -s https://downloads.apache.org/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5-bin.tar.gz.sha512) apache-maven-3.9.5-bin.tar.gz" | \
      sha512sum -c
apache-maven-3.9.5-bin.tar.gz: OK

It means it was confirmed that the server checksum was equal to the local one:

console
$ # checksum of the downloaded file
$ sha512sum apache-maven-3.9.5-bin.tar.gz
4810523ba025104106567d8a15a8aa19db35068c8c8be19e30b219a1d7e83bcab96124bf86dc424b1cd3c5edba25d69ec0b31751c136f88975d15406cab3842b  apache-maven-3.9.5-bin.tar.gz

Place files Place files

Extract it:

console
$ tar xzf apache-maven-3.9.5-bin.tar.gz

The result is as below:

console
$ ls {.,apache-maven-3.9.5}
.:
apache-maven-3.9.5/            apache-maven-3.9.5-bin.tar.gz
(...)

apache-maven-3.9.5:
bin/  boot/  conf/  lib/  LICENSE  NOTICE  README.txt

Now you have apache-maven-3.9.5 directory which contains bin etc. 👍

Set environment variables Set environment variables

Update PATH to include Maven bin:

console
$ # case bash
$ export PATH=$(readlink -f ./apache-maven-3.9.5/bin):$PATH
$ # case fish
$ #set -x PATH $(readlink -f ./apache-maven-3.9.5/bin/):$PATH

Conclusion Conclusion

Now Apache Maven is in your hands:

console
$ mvn --version
Maven home: /(...)/apache-maven-3.9.5
Java version: 21, vendor: Oracle Corporation, runtime: /(...)/jdk-21
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "6.1.0-13-amd64", arch: "amd64", family: "unix"

Let’s create an example project named “maven-example-01” and run it:

console
$ # create a project
$ mvn archetype:generate \
      -DarchetypeArtifactId=maven-archetype-quickstart \
      -DinteractiveMode=false \
      -DgroupId=com.myexample.app \
      -DartifactId=maven-example-01

$ # files are generated
$ cat src/main/java/com/myexample/app/App.java
package com.myexample.app;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
}

$ # build it
$ mvn package

$ # run
$ java -cp \
      target/maven-example-01-1.0-SNAPSHOT.jar \
      com.myexample.app.App
Hello World!

Yay 🙌

More on: Web and back-end development

Scqr [secureal]

Scqr [secureal]: the engineering practice of Reflerd Inc. (opens in a new tab)

Comments and feedback are welcome.