Configs

Java Java

Check existing Java installation

On some Linux distros, Java comes installed by default; however it is just the JRE and not the JDK. You can verify this as java command is found but the javac command is NOT found.

java --version  # OR "java -version" for older java
javac --version

Refer these articles to know the differences between JDK, JRE and JVM:

In Fedora, the JREs/JDKs are stored within /usr/lib/jvm. So you can look into it’s contents or query them as:

find /usr/lib/jvm -name java
find /usr/lib/jvm -name javac

Installing an OpenJDK OpenJDK

I’m on Fedora where the package manager is dnf. You would be installing your desired OpenJDK via your respective Linux distro’s package manager (like apt for Ubuntu/Debian):

Here's my list of packages output for dnf search openjdk (as of Jun 2025): ```sh Matched fields: name, summary ant-openjdk21.noarch: ant binding for openjdk21 java-21-openjdk.x86_64: OpenJDK 21 Runtime Environment java-21-openjdk-demo.x86_64: OpenJDK 21 Demos java-21-openjdk-demo-fastdebug.x86_64: OpenJDK 21 Demos optimised with full debugging on java-21-openjdk-demo-slowdebug.x86_64: OpenJDK 21 Demos unoptimised with full debugging on java-21-openjdk-devel.x86_64: OpenJDK 21 Development Environment java-21-openjdk-devel-fastdebug.x86_64: OpenJDK 21 Development Environment optimised with full debugging on java-21-openjdk-devel-slowdebug.x86_64: OpenJDK 21 Development Environment unoptimised with full debugging on java-21-openjdk-fastdebug.x86_64: OpenJDK 21 Runtime Environment optimised with full debugging on java-21-openjdk-headless.x86_64: OpenJDK 21 Headless Runtime Environment java-21-openjdk-headless-fastdebug.x86_64: OpenJDK 21 Runtime Environment optimised with full debugging on java-21-openjdk-headless-slowdebug.x86_64: OpenJDK 21 Runtime Environment unoptimised with full debugging on java-21-openjdk-javadoc.x86_64: OpenJDK 21 API documentation java-21-openjdk-javadoc-zip.x86_64: OpenJDK 21 API documentation compressed in a single archive java-21-openjdk-jmods.x86_64: JMods for OpenJDK 21 java-21-openjdk-jmods-fastdebug.x86_64: JMods for OpenJDK 21 optimised with full debugging on java-21-openjdk-jmods-slowdebug.x86_64: JMods for OpenJDK 21 unoptimised with full debugging on java-21-openjdk-portable.x86_64: OpenJDK 21 Runtime Environment portable edition java-21-openjdk-portable-devel.x86_64: OpenJDK 21 Development Environment portable edition java-21-openjdk-portable-devel-fastdebug.x86_64: OpenJDK 21 Runtime and Development Environment portable edition optimised with full debugging on java-21-openjdk-portable-devel-slowdebug.x86_64: OpenJDK 21 Runtime and Development Environment portable edition unoptimised with full debugging on java-21-openjdk-portable-docs.x86_64: OpenJDK 21 API documentation java-21-openjdk-portable-fastdebug.x86_64: OpenJDK 21 Runtime Environment portable edition optimised with full debugging on java-21-openjdk-portable-misc.x86_64: OpenJDK 21 miscellany java-21-openjdk-portable-slowdebug.x86_64: OpenJDK 21 Runtime Environment portable edition unoptimised with full debugging on java-21-openjdk-portable-sources.x86_64: OpenJDK 21 full patched sources of portable JDK java-21-openjdk-portable-static-libs.x86_64: OpenJDK 21 libraries for static linking - portable edition java-21-openjdk-portable-static-libs-fastdebug.x86_64: OpenJDK 21 libraries for static linking - portable edition optimised with full debugging on java-21-openjdk-portable-static-libs-slowdebug.x86_64: OpenJDK 21 libraries for static linking - portable edition unoptimised with full debugging on java-21-openjdk-portable-unstripped.x86_64: The OpenJDK 21 runtime environment. java-21-openjdk-slowdebug.x86_64: OpenJDK 21 Runtime Environment unoptimised with full debugging on java-21-openjdk-src.x86_64: OpenJDK 21 Source Bundle java-21-openjdk-src-fastdebug.x86_64: OpenJDK 21 Source Bundle for packages with debugging on and optimisation java-21-openjdk-src-slowdebug.x86_64: OpenJDK 21 Source Bundle for packages with debugging on and no optimisation java-21-openjdk-static-libs.x86_64: OpenJDK 21 libraries for static linking java-21-openjdk-static-libs-fastdebug.x86_64: OpenJDK 21 libraries for static linking optimised with full debugging on java-21-openjdk-static-libs-slowdebug.x86_64: OpenJDK 21 libraries for static linking unoptimised with full debugging on java-latest-openjdk.x86_64: OpenJDK 24 Runtime Environment java-latest-openjdk-demo.x86_64: OpenJDK 24 Demos java-latest-openjdk-demo-fastdebug.x86_64: OpenJDK 24 Demos optimised with full debugging on java-latest-openjdk-demo-slowdebug.x86_64: OpenJDK 24 Demos unoptimised with full debugging on java-latest-openjdk-devel.x86_64: OpenJDK 24 Development Environment java-latest-openjdk-devel-fastdebug.x86_64: OpenJDK 24 Development Environment optimised with full debugging on java-latest-openjdk-devel-slowdebug.x86_64: OpenJDK 24 Development Environment unoptimised with full debugging on java-latest-openjdk-fastdebug.x86_64: OpenJDK 24 Runtime Environment optimised with full debugging on java-latest-openjdk-headless.x86_64: OpenJDK 24 Headless Runtime Environment java-latest-openjdk-headless-fastdebug.x86_64: OpenJDK 24 Runtime Environment optimised with full debugging on java-latest-openjdk-headless-slowdebug.x86_64: OpenJDK 24 Runtime Environment unoptimised with full debugging on java-latest-openjdk-javadoc.x86_64: OpenJDK 24 API documentation java-latest-openjdk-javadoc-zip.x86_64: OpenJDK 24 API documentation compressed in a single archive java-latest-openjdk-jmods.x86_64: JMods for OpenJDK 24 java-latest-openjdk-jmods-fastdebug.x86_64: JMods for OpenJDK 24 optimised with full debugging on java-latest-openjdk-jmods-slowdebug.x86_64: JMods for OpenJDK 24 unoptimised with full debugging on java-latest-openjdk-portable.x86_64: OpenJDK 24 Runtime Environment portable edition java-latest-openjdk-portable-devel.x86_64: OpenJDK 24 Development Environment portable edition java-latest-openjdk-portable-devel-fastdebug.x86_64: OpenJDK 24 Runtime and Development Environment portable edition optimised with full debugging on java-latest-openjdk-portable-devel-slowdebug.x86_64: OpenJDK 24 Runtime and Development Environment portable edition unoptimised with full debugging on java-latest-openjdk-portable-docs.x86_64: OpenJDK 24 API documentation java-latest-openjdk-portable-fastdebug.x86_64: OpenJDK 24 Runtime Environment portable edition optimised with full debugging on java-latest-openjdk-portable-misc.x86_64: OpenJDK 24 miscellany java-latest-openjdk-portable-slowdebug.x86_64: OpenJDK 24 Runtime Environment portable edition unoptimised with full debugging on java-latest-openjdk-portable-sources.x86_64: OpenJDK 24 full patched sources of portable JDK java-latest-openjdk-portable-static-libs.x86_64: OpenJDK 24 libraries for static linking - portable edition java-latest-openjdk-portable-static-libs-fastdebug.x86_64: OpenJDK 24 libraries for static linking - portable edition optimised with full debugging on java-latest-openjdk-portable-static-libs-slowdebug.x86_64: OpenJDK 24 libraries for static linking - portable edition unoptimised with full debugging on java-latest-openjdk-portable-unstripped.x86_64: The OpenJDK 24 runtime environment. java-latest-openjdk-slowdebug.x86_64: OpenJDK 24 Runtime Environment unoptimised with full debugging on java-latest-openjdk-src.x86_64: OpenJDK 24 Source Bundle java-latest-openjdk-src-fastdebug.x86_64: OpenJDK 24 Source Bundle for packages with debugging on and optimisation java-latest-openjdk-src-slowdebug.x86_64: OpenJDK 24 Source Bundle for packages with debugging on and no optimisation java-latest-openjdk-static-libs.x86_64: OpenJDK 24 libraries for static linking java-latest-openjdk-static-libs-fastdebug.x86_64: OpenJDK 24 libraries for static linking optimised with full debugging on java-latest-openjdk-static-libs-slowdebug.x86_64: OpenJDK 24 libraries for static linking unoptimised with full debugging on maven-openjdk21.noarch: maven binding for openjdk21 openjdk-asmtools-javadoc.noarch: Javadoc for openjdk-asmtools openjdk-asmtools7-javadoc.noarch: Javadoc for openjdk-asmtools7 xmvn-toolchain-openjdk21.noarch: xmvn-minimal binding for openjdk21 Matched fields: name javapackages-local-openjdk21.noarch: Non-essential macros and scripts for Java packaging support maven-local-openjdk21.noarch: Macros and scripts for Maven packaging support openjdk-asmtools.noarch: Set of tools used to assemble / disassemble proper and improper Java .class files openjdk-asmtools7.noarch: Set of tools used to assemble / disassemble proper and improper Java .class files for JDK version 11 and lesser ```

Since Fedora 42, the Adoptium repository has been added to replace the older OpenJDK packages. Those JDKs are now available within the Eclipse temurin repository. Follow their Fedora Instructions to add temurin repo and install it’s older JDKs:

Installing an Oracle JDK

Installing JDKs via IntelliJ

You can also install JDKs from within IntelliJ itself:

IntelliJ auto-detects your available JDK locations on your system. You can also add your existing JDK folder locations like /usr/lib/jvm/jdk-11-oracle-x64 under configured JDKs in Project Structure


Working with multiple Java installations

The update-alternatives command in Linux (also called just alternatives in Fedora) creates, removes, maintains and displays information about the symbolic links comprising the alternatives system.

It is possible for several programs fulfilling the same or similar functions to be installed on a single system at the same time. A generic name in the filesystem is shared by all files providing interchangeable functionality. The alternatives system helps determine which actual file is referenced by this generic name.

Useful references:

When you install OpenJDK via your package manager or Oracle-JDK from the downloaded file, the alternatives should automatically get updated during that process

View available options for a command

update-alternatives --display java

The output would look like:

java - status is manual.
 link currently points to /usr/lib/jvm/java-21-openjdk-21.0.4.0.7-2.fc40.x86_64/bin/java
/usr/lib/jvm/java-21-openjdk-21.0.4.0.7-2.fc40.x86_64/bin/java - family java-21-openjdk.x86_64 priority 21000407
 ... follower links ...
/usr/lib/jvm/jdk-11.0.24-oracle-x64/bin/java - priority 184745984
 ... follower links ...
/usr/lib/jvm/java-22-openjdk-22.0.2.0.9-1.rolling.fc40.x86_64-fastdebug/bin/java - family java-latest-openjdk.x86_64 priority 1
 ... follower links ...
Current `best' version is /usr/lib/jvm/jdk-11.0.24-oracle-x64/bin/java.

Similarly, see alternative options list for javac

Adding an alternatives entry for a command

If any alternative for your commands is NOT registered in the list, you can manually add them as:

sudo update-alternatives --install <link> <name> <path> <priority>

For example, I downloaded the JetBrains Runtime (JCEF) JDK from within IntelliJ, which was downloaded at ~/.jdks/jbrsdk_jcef-17.0.12/ folder; but it was not showing up in the alternatives list. So, I’ll add the alternatives for java and javac as:

sudo update-alternatives --install /usr/bin/java java ~/.jdks/jbrsdk_jcef-17.0.12/bin/java 138
sudo update-alternatives --install /usr/bin/javac javac ~/.jdks/jbrsdk_jcef-17.0.12/bin/javac 138

Similarly, add alternatives for more commands like jar, javadoc etc. as required

You can also add follower links as:

--install link name path priority [--follower link name path]... [--initscript service] [--family name]

Switching between available alternatives of a command

Pick between Java installations present

sudo update-alternatives --config java

The output would look like below. Note that * denotes best available version and + denotes your current selection:

There are 4 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
 + 1           java-latest-openjdk.x86_64 (/usr/lib/jvm/java-23-openjdk-23.0.0.0.37-1.rolling.fc40.x86_64-fastdebug/bin/java)
*  2           /usr/lib/jvm/jdk-11.0.24-oracle-x64/bin/java
   3           java-21-openjdk.x86_64 (/usr/lib/jvm/java-21-openjdk-21.0.5.0.11-1.fc40.x86_64/bin/java)
   4           /home/kumar/.jdks/jbrsdk_jcef-17.0.12/bin/java

Enter to keep the current selection[+], or type selection number:

Similarly, choose among the alternative options for javac

When you uninstall/remove your JDK packages, remember to delete the respective alternatives entries

Removing an alternatives entry

For example, to remove the JCEF JDK’s java command alternative entry:

sudo update-alternatives --remove java ~/.jdks/jbrsdk_jcef-17.0.12/bin/java

Add Java to PATH

This should not be necessary if you are following the update-alternatives method to manage between Java installations and all entries are complete

However, to manually set the configuration in your shell profile, you can do as below: