DEV Community

Hrn Svncハルン
Hrn Svncハルン

Posted on • Updated on

How to change your Java and javac version on Ubuntu / Linux

In this short post i will show you how to easily change your java version and your java compiler version on your Ubuntu / Linux machine.

If you have installed more than one version of java on your system, you still have the opportunity to switch between different versions. Maybe you wanted to check out the newest features of the new java version or you have some kind of old project that only works for some older version (yes i know java ist a wora language but anyway).

If that is the case try the following commands:

$ update-alternatives --config java

$ update-alternatives --config javac

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                           Priority   Status
* 0            /usr/lib/jvm/java-11-openjdk-armhf/bin/java    1061      auto mode
  1            /usr/lib/jvm/java-11-openjdk-armhf/bin/java    1044      manual mode
  2            /usr/lib/jvm/java-8-openjdk-armhf/jre/bin/java 1061      manual mode

Press enter to keep the current choice[*], or type selection number:
Enter fullscreen mode Exit fullscreen mode

After choosing one of the numbers you will be good to go.

✅ If post was helpful you could try following me on
💻 or check out my new blog

Top comments (3)

rajmohan6268 profile image


rajmohan6268 profile image

if u still return error try with sudo and follwing command
$ sudo update-alternatives --config java
$ sudo update-alternatives --config javac

dgpickett profile image
David G. Pickett

I installed jdk18 but it does not show under java or javac. /etc/alternatives has a slew of linkes to my older java-17-openjdk-amd64. Does openjdk conflict with jdk?