60

I installed Ubuntu on my computer, and now my Java version is not updated. I have Java, so I don't need to install - just update the current version.

Can someone please tell me the command I have to use to get the current version?

I have tried: apt-get update and apt-get upgrade.

NotTheDr01ds
  • 22,082
kenneth
  • 677

8 Answers8

71

Note: WebUpd8 team's PPA has been discontinued with effective from April 16, 2019. Thus this PPA doesn't have any Java files. More information can be found on PPA's page on Launchpad. Hence this method no longer works and exists because of historical reasons.

Use ppa :

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

if you want java8 :

sudo apt-get install oracle-java8-installer

If you ABSOLUTELY need to have the latest update of java you must manualy install from official source, follow this tuto : http://www.cyberciti.biz/faq/howto-installing-oracle-java7-on-ubuntu-linux/

But I advise you to wait as ppa update

Kulfy
  • 18,154
Nymeria
  • 1,435
14

Today (2022/Nov), I just reach it with one command line:

apt install openjdk-17-jdk openjdk-17-jre
titoih
  • 323
9

Found something useful here..

Installing Java with apt-get is easy. First, update the package index:

 sudo apt-get update

Check if Java is not already installed:

 java -version

Then install java jre/jdk :

 sudo apt-get install default-jre

 sudo apt-get install default-jdk

For details please go to : https://www.digitalocean.com/community/tutorials/how-to-install-java-on-ubuntu-with-apt-get

4

Note: WebUpd8 team's PPA has been discontinued with effective from April 16, 2019. Thus this PPA doesn't have any Java files. More information can be found on PPA's page on Launchpad. Hence this method no longer works and exists because of historical reasons.

The newest OpenJDK Java packaged for trusty (14.04) right now is 7u55. You can check your Java version with java -version from the command line in Terminal.

If you want a newer one your best options will be to:

  • wait for an update from Ubuntu, OR

  • install the Oracle distribution of Java which currently is at 7u65:

    sudo add-apt-repository ppa:webupd8team/java
    sudo apt-get update
    sudo apt-get install oracle-java7-installer
    
Kulfy
  • 18,154
akafred
  • 65
  • 1
2

Many complicated and version dependent answers here, thus I write this reply to avoid coming again here via Google and going through all this drama.

The OP original questions is "How to upgrade Java on Ubuntu", hence I assume to the latest version.

  1. Find the latest available version in APT using

    apt install openjdk-Tab

    Example output:

    openjdk-11-dbg           openjdk-17-jdk-headless  openjdk-21-source
    openjdk-11-demo          openjdk-17-jre           openjdk-21-testsupport
    openjdk-11-doc           openjdk-17-jre-headless  openjdk-8-dbg
    openjdk-11-jdk           openjdk-17-jre-zero      openjdk-8-demo
    openjdk-11-jdk-headless  openjdk-17-source        openjdk-8-doc
    openjdk-11-jre           openjdk-21-dbg           openjdk-8-jdk
    openjdk-11-jre-headless  openjdk-21-demo          openjdk-8-jdk-headless
    openjdk-11-jre-zero      openjdk-21-doc           openjdk-8-jre
    openjdk-11-source        openjdk-21-jdk           openjdk-8-jre-headless
    openjdk-17-dbg           openjdk-21-jdk-headless  openjdk-8-jre-zero
    openjdk-17-demo          openjdk-21-jre           openjdk-8-source
    openjdk-17-doc           openjdk-21-jre-headless  
    openjdk-17-jdk           openjdk-21-jre-zero
    
  2. By the time of my writing the latest is v21, hence I run (change according to your result)

    sudo apt install openjdk-21-jdk or sudo apt install openjdk-21-jre

  3. Update alternatives to be sure you're using the latest version

    sudo update-alternatives --config java

    sudo update-alternatives --config javac

  4. Confirm it

    java --version

    javac --version

karel
  • 122,292
  • 133
  • 301
  • 332
2

Don't know why everyone has answered with oracle, but here is open jdk:

sudo apt-get install openjdk-7-jre

http://openjdk.java.net/install/

Blundell
  • 129
1

Updated for Ubuntu 18.04

Use ppa :

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

For more infos see: http://www.webupd8.org/2014/03/how-to-install-oracle-java-8-in-debian.html

if you want java9: (Now some Programs like JabRef still need Java8)

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java9-installer

On http://www.webupd8.org/2015/02/install-oracle-java-9-in-ubuntu-linux.html you can see a detailed explanation how to install Java9, and how to change it to default.

if you want Java 10:

sudo add-apt-repository ppa:linuxuprising/java
sudo apt update
sudo apt install oracle-java10-installer

For more infos see: https://www.linuxuprising.com/2018/04/install-oracle-java-10-in-ubuntu-or.html

if you want Java 11:

sudo apt install openjdk-11-jre-headless
sudo apt install openjdk-11-jdk

If you need the latest update you can download it from

If you have problems to install the latest updates see: https://www.cyberciti.biz/faq/howto-installing-oracle-java7-on-ubuntu-linux/

This question uses content from

JoKalliauer
  • 1,674
  • 2
  • 20
  • 27
1

Another possible solution is to add the PPA repository from the project ubuntu-justched available in the Github. This will provide a little bit different solution because it will download the Oracle JRE tarball to a previously configured directory and generate a DEB package from it.

That way you won't depend on somebody else packing the JRE, you will do it yourself (don't worry, it will be an automatic process).

0xF2
  • 3,155