Assuming one has installed a JDK in /opt/java/jdk1.8.0_144 then:

  1. Install the alternative for javac

    $ sudo update-alternatives --install /usr/bin/javac javac /opt/java/jdk1.8.0_144/bin/javac 1
    
  2. Check / update the alternatives config:

    $ sudo update-alternatives --config javac
    

If there is only a single alternative for javac you will get a message saying so, otherwise select the option for the new JDK.

To check everything is setup correctly then:

$ which javac
/usr/bin/javac

$ ls -l /usr/bin/javac
lrwxrwxrwx 1 root root 23 Sep  4 17:10 /usr/bin/javac -> /etc/alternatives/javac

$ ls -l /etc/alternatives/javac
lrwxrwxrwx 1 root root 32 Sep  4 17:10 /etc/alternatives/javac -> /opt/java/jdk1.8.0_144/bin/javac

And finally

$ javac -version
javac 1.8.0_144

Repeat for java, keytool, jar, etc as needed.

Answer from Richard Grimshaw on Stack Overflow
Top answer
1 of 12
84

Assuming one has installed a JDK in /opt/java/jdk1.8.0_144 then:

  1. Install the alternative for javac

    $ sudo update-alternatives --install /usr/bin/javac javac /opt/java/jdk1.8.0_144/bin/javac 1
    
  2. Check / update the alternatives config:

    $ sudo update-alternatives --config javac
    

If there is only a single alternative for javac you will get a message saying so, otherwise select the option for the new JDK.

To check everything is setup correctly then:

$ which javac
/usr/bin/javac

$ ls -l /usr/bin/javac
lrwxrwxrwx 1 root root 23 Sep  4 17:10 /usr/bin/javac -> /etc/alternatives/javac

$ ls -l /etc/alternatives/javac
lrwxrwxrwx 1 root root 32 Sep  4 17:10 /etc/alternatives/javac -> /opt/java/jdk1.8.0_144/bin/javac

And finally

$ javac -version
javac 1.8.0_144

Repeat for java, keytool, jar, etc as needed.

2 of 12
76

You will notice a big change when selecting options if you type in "java -version" after doing so. So if you run update-alternatives --config java and select option 3, you will be using the Sun implementation.
Also, with regards to auto vs manual mode, making a selection should take it out of auto mode per this page stating:

When using the --config option, alternatives will list all of the choices for the link group of which given name is the master link. You will then be prompted for which of the choices to use for the link group. Once you make a change, the link group will no longer be in auto mode. You will need to use the --auto option in order to return to the automatic state.

And I believe auto mode is set when you install the first/only JRE/JDK.

🌐
Igalia
blogs.igalia.com › dpino › 2011 › 10 › 13 › configuring-different-jdks-with-alternatives
Configuring different JDKs with alternatives - Unweaving the Web
* as *‘java’*, then when later we do: ‘*alternatives –config java*‘, the alternatives for ‘*java*‘ will be listed.
Top answer
1 of 4
213
sudo update-alternatives --config java

Configures the default for the program "java". That's the Java VM.

sudo update-alternatives --config javac

Configures the default Java compiler.

You can also see that, because the first command lists a lot of "JRE" (Java Runtime Environment) folders and the Program is just called "java".

If I check which version is being used by issuing the command java -version or javac -version, I can see, that each command changes the program being used.

However, using update-java-alternatives with a JDK Version changes both programs for me. Using the first commands, you can use a Java VM and Java Compiler from different JDKs.

update-java-alternatives requires presence of a file with extension .jinfo in directory /usr/lib/jvm. The openjdk package is shipped with a .jinfo file, the jdk of Oracle (formerly Sun) is not. As alternative, you configure alternatives without update-java-alternatives:

For example, to add java from jvm-directory /usr/lib/jvm/jdk-12.0.1 (default directory of Debian package of Oracle) with priority 2082, use the following command:

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-12.0.1/bin/java 2082

As for switching for different development environments:

Are you talking about starting the IDE itself with different Java versions or using different versions in the IDE for compilation and running your app?

  • For 1.: You can specify which JVM to use in the eclipse.ini, as described here. I don't know how to do that for the Arduino IDE.

  • For 2.: In Eclipse you can select the JRE/JDK to be used in Window -> Preferences -> Java -> Installed JREs. And under Java -> Compiler you could choose an older Java compliance if you wish.

EDIT: This DigitalOcean page also has a very nice explanation of everything related to Java on Ubuntu.

2 of 4
36

update-java-alternatives is a program to update alternatives for jre/jdk installations.

update-alternatives is a symbolic link management system for linux (I'm sure there is little news here).

You can, and really should, use both update-java-alternatives and update-alternatives together.

Firstly, be sure to have the all the alternatives configured correctly. java and javac are but a few. There is javadoc, rmic, serialver and others, substituting the above variables for: native2ascii and /opt/jdk1.8.0_40/bin/native2ascii should report if the alternative is installed and/or selected.

When all the alternatives are configured you can then create links in /usr/lib/jvm to your manual instalation.

In order to configure update-java-alternatives you must use a hidden file with the same name as your directory but prefixed by a . (dot).

Hope this helps.

Bibliography

man -S 8 update-java-alternatives

http://tech.lanesnotes.com/2008/03/using-alternatives-in-linux-to-use.html

https://stackoverflow.com/questions/6477415/how-to-set-oracles-java-as-the-default-java-in-ubuntu

🌐
AppDesk Services
appdeskservices.com › home › top 8 java alternatives
Top 8 Java Alternatives - 2024
April 28, 2026 - Are you tired of the same old Java? Venture into a world of diverse languages built for the JVM, each offering unique strengths. Best Java Alternatives are...
🌐
Baeldung
baeldung.com › home › installation › switch between multiple java versions
Switch Between Multiple Java Versions | Baeldung on Linux
March 18, 2024 - $ update-java-alternatives --list java-1.17.0-openjdk-amd64 1711 /usr/lib/jvm/java-1.17.0-openjdk-amd64 java-1.21.0-openjdk-amd64 2111 /usr/lib/jvm/java-1.21.0-openjdk-amd64 java-1.8.0-openjdk-amd64 1081 /usr/lib/jvm/java-1.8.0-openjdk-amd64
🌐
Hackr
hackr.io › home › articles › programming
Java Alternatives: The Most Popular Java Competitors of 2026
January 30, 2025 - Looking for an alternative to Java? We cover the ten best Java alternatives, from Kotlin to Go.
🌐
Slashdot
slashdot.org › software › p › Java › alternatives
Top Java Alternatives in 2026
Amazon Corretto is a free, multiplatform, production-ready distribution of the Open Java Development Kit (OpenJDK). It offers long-term support that encompasses ongoing performance improvements and essential security updates. Widely utilized within Amazon’s own production environment, Corretto operates seamlessly on a multitude of services and is certified for compatibility with the Java SE standard.
Rating: 5 ​ - ​ 1 votes
Find elsewhere
🌐
ITAA
itaa.com › home › the best oracle java alternatives in 2026 – and how to transition
The Best Oracle Java Alternatives in 2026 – and How to Transition - ITAA
2 weeks ago - This article explores the most widely adopted alternatives, how they compare, and how to plan a smooth, risk-free transition. We’ve also included a practical Oracle Java Licensing Guide at the end of this article to help you assess potential cost, compliance, and migration risks within your own environment.
🌐
Linux find Examples
queirozf.com › entries › update-alternatives-changing-java-version-on-ubuntu
Update Alternatives: Changing Java version on Ubuntu
May 2, 2022 - $ sudo update-alternatives --list java /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
🌐
Back4App
blog.back4app.com › home › learn › top 10 java alternatives
Top 10 Java Alternatives - Which is the best?
December 14, 2023 - This article will explore ten of the best Java alternatives. The list includes Kotlin, Python, Scala, Golang, Rust, Javascript, etc.
🌐
Ming's Blog
bitmingw.com › 2019 › 08 › 28 › ubuntu-update-alternatives
Changing the Default Program with update alternatives | Ming's Blog
January 1, 2026 - To list all entries of alternatives in the system, use update-alternatives --get-selections. You can see java is pointing to actual program at /usr/lib/jvm/java-11-openjdk-amd64/bin/java, which belongs to JDK 11.
🌐
DEV Community
dev.to › thegroo › install-and-manage-multiple-java-versions-on-linux-using-alternatives-5e93
Install and manage multiple Java versions on Linux using alternatives - DEV Community
February 10, 2022 - sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/azul-open-jdk-17/bin/javac 2 ... sudo update-alternatives --install /usr/bin/jshell jshell /usr/lib/jvm/azul-open-jdk-17/bin/jshell 2 · Now that you have the new JDK installed and configured you can easily switch between versions using: ... Pick the number of the version you want from the Selection list.
🌐
AlternativeTo
alternativeto.net › software › java
Best Java Alternatives: Top Programming Languages in 2025 | AlternativeTo
The best Java alternatives are Python, JavaScript and C++. Our crowd-sourced lists contains more than 50 apps similar to Java for Linux, Windows, Mac, BSD and more.
🌐
ExamSnap
examsnap.com › home › top java alternatives in 2025: explore the best programming languages beyond java
Top Java Alternatives in 2025: Explore the Best Programming Languages Beyond Java - ExamSnap
December 15, 2025 - JavaScript dominates the web development space. C++ offers low-level control for high-performance needs · Dart enables cross-platform development. ... Choosing the right language involves evaluating technical requirements, team expertise, and long-term goals. The right fit enhances productivity, maintainability, and innovation in software development. As the software development ecosystem evolves, the need for alternatives to Java continues to grow.
🌐
SourceForge
sourceforge.net › software › product › Java › alternatives
Best Java Alternatives & Competitors
Compare the best Java alternatives in 2025. Explore user reviews, ratings, and pricing of alternatives and competitors to Java.
Rating: 5 ​ - ​ 1 votes
🌐
TMS Outsource
tms-outsource.com › home › top java alternatives for modern developers
Top Java Alternatives for Modern Developers - TMS Outsource
April 3, 2026 - This guide examines top Java substitutes that balance familiarity with innovation. We’ll compare options ranging from JVM languages like Kotlin and Scala to completely different ecosystems including Python, Go, and C#. You’ll discover which alternatives excel for web development, mobile development, and backend development while learning about crucial factors like community support, hiring market demand, and language adoption trends.
🌐
Bell Software
bell-sw.com › blog › oracle-java-alternatives-comparison-of-openjdk-distributions
Alternatives to Oracle Java — Overview of OpenJDK Distributions (2026)
April 21, 2026 - Compare the best Oracle Java alternatives in 2026 — Liberica JDK, Temurin, Corretto, Azul Zulu, and more. Free, TCK-verified OpenJDK distributions reviewed side by side.
🌐
Red Hat
access.redhat.com › solutions › 6232511
How to set default Java version with alternatives tool in RHEL on a per user basis - Red Hat Customer Portal
5 days ago - When different Java versions are installed on a RHEL system, using the alternatives tool as a regular user fails to set the default version. # alternatives --config java There is 2 program that provides 'java'. Selection Command ----------------------------------------------- *+ 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el8_4.x86_64/jre/bin/java) 2 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.11.0.9-2.el8_4.x86_64/bin/java) Enter to keep the current selection[+], or type selection number: 2 failed to create /var/lib/alternatives/java.new: Permission denied Using the alternatives tool allows you to set the system default version as root but does not currently provide options to set different defaults for individual users.
🌐
Coursesity
coursesity.com › blog › top-java-alternatives
Top Java Alternatives in 2025 : 15 Programming Language
December 27, 2024 - Alternatives such as C#, Python, and JavaScript are popular choices for developing web and mobile applications. These languages can provide different advantages over Java, such as better performance, more features, and more flexibility.