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.

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

Discussions

ChatGPT alternatives?
There hasn’t been a performance decline, just expectations inflation. More on reddit.com
🌐 r/ChatGPTPro
46
21
July 21, 2023
Instancio 2.2.0 released
How do you deal with recursive data structure? do you have a recursive limit or it will go in infinite loop ? I would love to see the possibility to populate data field like stream (Address::street) instead of using string value (Address.class, "street") I hate using string value for field, it's so fragile with refactoring More on reddit.com
🌐 r/java
18
60
January 4, 2023
What are your thoughts on Spring in 2023?
I can spin up a microservice within 10min with DB connection, Rest endpoint, basic security, etc Still love SpringBoot… More on reddit.com
🌐 r/java
119
96
January 27, 2023
What free alternatives for Heroku are there when it comes to Java Spring Boot application without using Docker and GitHub?
Maybe take a look at https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier.sort-order=asc&awsf.Free%20Tier%20Types= all&awsf.Free%20Tier%20Categories=all Or https://cloud.google.com/free/ Or https://azure.microsoft.com/en-gb/free/ All of the above provide a year of free computing system, good enough to run spring boot. And all of them provide almost complete control of the box, so deployment is your choice. Having said, they are a bit tricker than heroku to wrap ones head around. More on reddit.com
🌐 r/Heroku
13
1
September 18, 2022
🌐
Igalia
blogs.igalia.com › dpino › 2011 › 10 › 13 › configuring-different-jdks-with-alternatives
Configuring different JDKs with alternatives - Unweaving the Web
What the hell means each parameter? This is pretty obscure if you don’t really understand what’s the purpose of the ‘*alternatives*‘ program. ... * as *‘java’*, then when later we do: ‘*alternatives –config java*‘, the alternatives for ‘*java*‘ will be listed.
🌐
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
🌐
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. Type in the Reference number for the one you want to be used from the displayed list and check with java -version ...
🌐
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.
🌐
Baeldung
baeldung.com › home › installation › switch between multiple java versions
Switch Between Multiple Java Versions | Baeldung on Linux
March 18, 2024 - We can enlist the available Java versions using the –config option: $ update-alternatives --config java There are 3 choices for the alternative java (providing /usr/bin/java).
Find elsewhere
Top answer
1 of 6
536
Confusing error messages: Clojure's error messages more often than not are very confusing. They usually involve stack traces that do not thoroughly explain where the error was caused or what caused it. | Immutability is the default: Clojure programmers are highly encouraged to use immutable data in their code. Therefore, most data will be immutable by default. · State change is handled by functions (for transformations) and atoms (an abstraction that encapsulates the idea of some entity having an identity). | Minimal syntax: Being a LISP, programs are simple: they're just functions and data. That it doesn't get bogged down with syntax or the loftier FP concepts like monads makes it one of most approachable functional languages for beginners. | Tries to solve problems as simply as possible: Simplicity is one of the pillars on which Clojure is built. Clojure tries to solve many problems in software development as simply as possible. Instead of building complex interfaces, objects or factories, it uses immutability and simple data structures. | Good for writing concurrent programs: Since Clojure is designed for concurrency, it offers things like Software Transaction Memory, functional programming without side-effects and immutable data structures right out of the box. This means that the development team can focus their energies on developing features instead of concurrency details. | Huge ecosystem of libraries to work with: There's a very large ecosystem of high-quality Clojure libraries which developers can use. One example is Incanter. It's a great data analytics library and a very powerful tool for dealing with matrices, datasets and csv files. | Code tends to be nightmare to maintain for non-authors: Tendency to devolve into difficult to manage mess of styles. Not recommended for professional use. | Too cult-ish: Way too niche and in-group behavior, while trying to trash other languages. Only pays for select few, who run the "game" on others. | Cross platform: Clojure compiles to JVM bytecode and runs inside the JVM. This means that applications written in Clojure are cross-platform out of the box. | Rich Hickey: The creator is so awesome, he's a feature. Just look up his talks and see why. | Dynamic language: A superb data processing language. While rich type and specification systems are available they are optional. | Tied to the JVM and it's limitations: Some language constructs were obviously created as workarounds for JVM limitations. This makes the language much less elegant than it could have been. · Also, the JVM has a very cumbersome FFI. | Syntax can be alien / jarring for those used to other Lisps: Perhaps some may consider this attribute an advantage, but I do not. Clojure does not attempt to maintain significant compatibility with other Lisps. So, if you already know a Lisp or are used to the way Lisp works in general, you'll probably be confused if you take a look at Clojure. See these resources for more details on this subject: · - https://clojure.org/reference/lisps · - http://stackoverflow.com/q/6008313/2636454 · - http://gilesbowkett.blogspot.com/2015/01/one-major-difference-between-clojure.html · - http://softwareengineering.stackexchange.com/q/153128/166211 | Extensible: Clojure has an elegant macro system which enables language additions, Domain-specific languages (DSLs), to be created much easier than most other languages (with the exception of Racket, perhaps). | Great tool used in automating, configuring and managing dependencies available: Leiningen is a very useful tool for Clojure developers. It helps wiht automation, configuration and dependency management. It's basically a must for every Clojure project. | No C/Java syntax: Refreshing, BTW! | Game is available with which you can learn Clojure: Nightmod is a tool used to make "live-moddable" games. It displays the game's code while you are playing and allows you to inject new code using Clojure. This can be a fun and useful experience for people trying to learn Clojure. | Dynamic types: You can put anything in. This makes reasoning about code after a time has passed very hard.
2 of 6
333
Statically typed programming language for the JVM, Android and the browser.Statically typed programming language for the JVM, Android and the browser.Great tooling support: Since Kotlin is made by Jetbrains (the developers of IntelliJ IDEA) so it stands to reason that the IntelliJ support for Kotlin is also great. Besides that, Kotlin also works well with existing Java tools such as Eclipse, Maven, Gradle, Android Studio, etc... | Easy adoption for existing Java programmers: Kotlin runs on the JVM and Java interoperability has been one of the main objectives since the language was born. It runs everywhere Java does; web servers, mobile devices (Android), and desktop applications. It also works with all the major tools in the Java ecosystem like Eclipse, IntelliJ, Maven, Ant, Gradle, Spring Boot, etc. · All of this makes adoption extremely easy even for existing Java projects. On top of this there's also ensured Type safety and less boilerplate code needed. | May be hard for programmers already used to imperative style to learn functional programming from Kotlin: Since Kotlin does not enforce any particular paradigms and is not purely functional, it can be pretty easy to fall back to imperative programming habits if a programmer comes from an imperative background. | Easy to learn if you have prior programming experience: Kotlin's syntax is extremely easy to understand. The language can be picked up in a few hours just by reading the language reference. | No runtime overhead: The standard library is relatively small and tight. It mostly consists of focused extensions of the Java standard library and as such adds no additional runtime overhead to existing Java projects. | Officially supported for Android development: Starting with version 3.0 of Android Studio, Kotlin support will be built-in. This means that it's now easier than ever to use Kotlin for existing Android projects or even start writing Android apps only with Kotlin from scratch. · This also means that Kotlin and Kotlin plugins for Android Studio will be fully supported in the future and their likelihood of being abandoned is quite small since Google is fully embracing the language for their Android ecosystem (alongside Java and C++). | Low-risk adoption for existing Java codebases: Since it has such a good interoperability with Java, Java libraries, and Java tools. It can be adopted for an existing Java codebase at little to no cost. The codebase can be converted from Java to Kotlin little by little without ever disrupting the functionality of the application itself. | Does not impose a particular philosophy of programming: It's not overly OOP like Java and it does not enforce strict functional paradigms either. | Is built to solve industrial problems: Kotlin has been designed and built by developers who have an industrial background and not an academic one. As such, it tries to solve issues mostly found in industrial settings. For example, the Kotlin type system helps developers avoid null pointer exceptions. Reasearch languages usually do not have `null` at all, but APIs and large codebases usually need `null`. | The need for Java interoperability has forced some limitations: The need to make Kotlin interoperable with Java has caused some unintuitive limitations to the language design.
🌐
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.
🌐
Slashdot
slashdot.org › software › p › Java › alternatives
Top Java Alternatives in 2026
Find the top alternatives to Java currently available. Compare ratings, reviews, pricing, and features of Java alternatives in 2026.
Rating: 5 ​ - ​ 1 votes
🌐
Ubuntu
manpages.ubuntu.com › trusty › man(8)
Ubuntu Manpage: update-java-alternatives - update alternatives for jre/sdk installations
A package does provide these information of it's alternatives in /usr/lib/jvm/.<jname>.jinfo. ... List all installed packages (or just <jname>) providing information to set a bunch of java alternatives.
🌐
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.
🌐
javaspring
javaspring.net › blog › java-alternative
Java Alternatives: A Comprehensive Guide — javaspring.net
Java alternatives like Kotlin, Scala, and Groovy offer unique features and benefits that can be valuable in different programming scenarios. Kotlin provides a modern and concise syntax with excellent Java interoperability.
🌐
Medium
medium.com › @ayeshajayasankha › how-to-install-and-switch-between-alternative-java-versions-66b3671fc382
How To Install And Switch Between Alternative Java Versions | by Ayesha Jayasankha | Medium
July 3, 2019 - sudo update-alternatives — set java <Directory where JAVA has been extracted>/bin/javasudo update-alternatives — set javac <Directory where JAVA has been extracted>/bin/ javacsudo update-alternatives — set javaws <Directory where 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.
🌐
OneUptime
oneuptime.com › home › blog › how to install and switch java versions on ubuntu
How to Install and Switch Java Versions on Ubuntu
March 2, 2026 - # Check if Java is installed and which version java -version # Check the compiler version javac -version # Find where Java is installed which java readlink -f $(which java) # Show all installed Java versions update-alternatives --list java
🌐
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 - In Part 1, we examined several major alternatives like Kotlin, Python, Rust, JavaScript, and C++. In this section, we broaden the scope by exploring even more programming languages that offer unique capabilities and are viable replacements for Java in various development scenarios.
🌐
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.
🌐
TutorialsPoint
tutorialspoint.com › article › java-alternatives
Java Alternatives
July 26, 2023 - C# is also a secure language and has similar syntax as that of Java. C# is compatible with Windows and Mac while Java is also compatible with Linux. Scala is a powerful language and is one of the best alternatives to Java.