Maven on Java 21 and Devuan 5 (Debian 12): Install manually
Tags: maven, java, openjdk, devuan
Published: 2023-10-15 04:00:17

## Summary

[Apache](https://apache.org/) [Maven](https://maven.apache.org/) is a popular open source software to build and manage projects of [Java](https://dev.java/) (and also other programming languages), licensed under [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0).

With [Devuan](https://www.devuan.org/) [5 Daedalus](https://www.devuan.org/os/announce/daedalus-release-announce-2023-08-14) based on [Debian](https://www.debian.org/) [12 bookworm](https://www.debian.org/releases/bookworm/), it is easy to use it thanks to [their packages management](https://packages.debian.org/bookworm/). However, it is not always the latest. Actually, Maven Debian 12 offers is currently [3.8](https://maven.apache.org/docs/3.8.1/release-notes.html) instead of [3.9](https://maven.apache.org/docs/3.9.0/release-notes.html). Well, is it a big problem ? Probably, no.

In [my previous post](https://scqr.net/en/blog/2023/10/14/java-21-on-devuan-5-debian-12-install-manually/index.html), I installed [OpenJDK](https://openjdk.org/) [21](https://jdk.java.net/21/), 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

- OS: Devuan 5 Daedalus
  - based on Debian 12
- App Engine: OpenJDK 21
- Project Build and Management: Apache Maven [3.9.5](https://maven.apache.org/docs/3.9.5/release-notes.html)

## 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

Visit: https://maven.apache.org/download.cgi

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

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

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

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 🙌