Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Switch Java Versions per Project: update-alternatives & JAVA_HOME

The JDK 21 release page lists general availability on 19 September 2023, and JDK 25 followed on 16 September 2025; both are long-term support releases from most vendors. Since then, many developers have ended up with both versions on one laptop: an older service that must stay on 21, and a newer project that wants 25. The trap is that changing the system default every time you switch repositories…

Java 21 and Java 25 have been available as long-term support releases since September 2023 and September 2025 respectively. Many developers now find themselves with both versions installed on a single machine, often when working on different projects requiring distinct Java versions. However, managing system-wide defaults and per-project setups can be cumbersome, as switching the system default each time you switch between repositories can become tedious, and discrepancies between `java -version` and your build tool remain unresolved.

This tutorial presents a three-tiered approach to managing multiple Java versions: system default, shell or directory override, and per-build pinning. The tutorial then details a step-by-step checklist to troubleshoot the common issue where Java 25 is installed, but Maven continues to compile with Java 21.

First, install both Java 21 and Java 25 side by side using Ubuntu's package archive. On Ubuntu 24.04, `openjdk-21-jdk` is the default JDK, while `openjdk-25-jdk` is available in the Universe repository. Enable Universe and update the package index before installing the JDK packages. The JDK packages include both the runtime and development tools, so a separate JRE is unnecessary if you only need to run existing Java applications.

Next, understand the three levels that determine the Java version used by your system:

1. System-wide default using `update-alternatives`: This method uses Debian's alternatives system to manage multiple Java installations. The `/usr/bin/java` and `/usr/bin/javac` executables are symbolic links to different JDK installations, controlled by `update-alternatives`. You can set the system default by choosing an entry with `update-alternatives --config java` and `update-alternatives --config javac`. However, this method may not be ideal for developers switching between projects frequently.

2. Per-shell or per-directory override using `JAVA_HOME`: Setting the `JAVA_HOME` environment variable to the desired JDK's `bin` directory allows the JDK to be used by newly launched tools. You can create a shell function, `use-java`, to quickly switch between Java versions, and use `direnv` to automatically apply the correct Java version within a directory. This method is more flexible for developers who work on different projects requiring different Java versions.

3. Per-build pinning using Maven toolchains or Gradle toolchains and the daemon JVM: This method involves specifying the JDK version to use for each build, regardless of the shell or directory settings. Maven's `toolchains` feature or Gradle's `toolchains` plugin allows you to pin the JDK version used for compilation, ensuring consistency across builds.

When diagnosing a version mismatch, follow this order:

1. Check the system-wide default by running `java -version` and `javac -version`.

2. Verify the `JAVA_HOME` environment variable and the corresponding `PATH` configuration.

3. Finally, inspect the build tool's toolchain configuration to ensure the correct JDK version is being used.

With this structured approach, developers can effectively manage multiple Java versions, ensuring compatibility across their projects without the hassle of constantly switching system defaults.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

Qdrant Tutorial: Search Your Shop by Meaning, Not Words

Quick answer Qdrant is a vector database: it stores items as lists of numbers called vectors and finds the closest matches to a query, so a search for a light summer kurta returns cotton kurtas even…

  • Qdrant is a vector database storing items as vectors
  • Enables finding closest matches to a query
  • Local database simplifies use without cloud account

Standardizing KMnO4 against Mohr's salt: a different n-factor, in JavaScript

KMnO4 can be standardized against two different reducing agents in Class 12 practicals: oxalic acid (a classic, needs heating) or Mohr's salt, FeSO4.(NH4)2SO4.6H2O (reacts at room temperature).

  • KMnO4 standardized using oxalic acid or Mohr's salt in Class 12 practicals
  • N-factor is 1 for Mohr's salt, 2 for oxalic acid in titration
  • Normality of KMnO4 remains consistent regardless of reducing agent used

Node.js 20 decommissioned: fix Firebase deploy

Node.js 20 decommissioned is why your Firebase deploy now fails. Google decommissioned the Node.js 20 runtime on 30 October 2026, so functions still set to Node.js 20 can no longer be created or…

  • Node.js 20 decommissioned on October 30, 2026
  • Firebase deploys fail for projects on Node.js 20
  • Update to Node.js 22 runtime to fix deploy issues

KT&G Expands Heated Tobacco Business in Indonesia with Launch of FLEX and FAIIM

KT&G is accelerating its global next-generation products (NGP) business by entering Indonesia’s heated tobacco market directly, following its recent expansion into Kazakhstan.The South Korean tobacco…

  • KT&G launches FLEX device and four FAIIM varieties in Indonesia.
  • Company expands heated tobacco operations in Jakarta and plans nationwide rollout.
  • Indonesia is KT&G's largest overseas cigarette market by sales volume.

More from Monday, 30 November 2026 →