This post explains how to install or update Java components JRE or JDK in operating system Ubuntu.
It may be compatible with other Debian-like or Ubuntu-like Linux distros, like Linux Mint, etc.
1. Install repository
Open a terminal.
Install repository from command line:
sudo add-apt-repository ppa:<repositoryaddress>
The repositories I found were (you need to substitute <repositoryaddress> by the corresponding address):
Neither of these repositories are official and I do not have feedback about them (apart from what I have read in some forums), so use them at your own risk.
So for example, to install the openjdk-r/ppa repository:
sudo add-apt-repository ppa:openjdk-r/ppa
2. Update apt-get
Run this command on terminal:
sudo apt-get update
3. Install JDK
Install the desired JDK from terminal.
If for example, you want to install OpenJDK 15:
sudo apt-get install openjdk-15-jre
sudo apt-get install openjdk-15-jdk
5. Check the Java version used as default
Go to the terminal and type:
Your current Java version must be displayed.
4. Select the default JDK version to use
In my case, I was updating from OpenJDK 11 to OpenJDK 15, and I did not need to apply any change in order to use the latest OpenJDK version. It was updated automatically.
You can also install multiple version of JDK, mixing OpenJDK and Oracle versions. Then you can use the command update-java-alternatives to switch between installed version:
# list available jdk update-java-alternatives --list # use jdk7 sudo update-java-alternatives --set java-7-oracle # use jdk8 sudo update-java-alternatives --set java-8-oracle
- “Ubuntu: OpenJDK 8 – Unable to locate package“; stackoverflow
- “Installing openjdk-15 returns with unable to locate package error“; stackoverflow