<\/span><\/h2>\n\n\n\nIn Ubuntu 24.04, the default Java development repository is set to Java 21. So, there is no need to download the repo, adding GPG keys manually. We can install Java Development Kit 21 with the following command:<\/p>\n\n\n\n
sudo apt install openjdk-21-jdk -y<\/pre>\n\n\n\nOnce installed, we can check the Java version with the command below:<\/p>\n\n\n\n
java -version<\/pre>\n\n\n\nYou should receive the following output:<\/p>\n\n\n\n
root@host:~# java -version\nopenjdk version \"21.0.2\" 2024-01-16\nOpenJDK Runtime Environment (build 21.0.2+13-Ubuntu-2)\nOpenJDK 64-Bit Server VM (build 21.0.2+13-Ubuntu-2, mixed mode, sharing)\n<\/pre>\n\n\n\n<\/span>3. Install Oracle Java<\/span><\/h2>\n\n\n\nOracle Java can not be installed with one command because it is not included in the default Ubuntu 24.04 repository. We need to download the package manually with the wget and install it. So, to download Oracle Java 21, execute the following command:<\/p>\n\n\n\n
wget https:\/\/download.oracle.com\/java\/21\/latest\/jdk-21_linux-x64_bin.deb<\/pre>\n\n\n\nOnce downloaded, you can install the package with the command below:<\/p>\n\n\n\n
sudo apt install .\/jdk-21_linux-x64_bin.deb<\/pre>\n\n\n\nIf you execute the command java -version<\/b>, you will get the same output as before:<\/p>\n\n\n\nroot@host:~# java -version\nopenjdk version \"21.0.2\" 2024-01-16\nOpenJDK Runtime Environment (build 21.0.2+13-Ubuntu-2)\nOpenJDK 64-Bit Server VM (build 21.0.2+13-Ubuntu-2, mixed mode, sharing)\n<\/pre>\n\n\n\nThis is because we installed Java OpenJDK 21 first, and it is set as the default version. In the next paragraph, we will explain how to switch between different versions of Java.<\/p>\n\n\n\n