To install the Java Development Kit (JDK) on Ubuntu 18.04, you can follow these steps:
apt-get
. To add the PPA, run the following command:sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
apt-get
. To install the JDK, run the following command:sudo apt-get install oracle-java8-installer
sudo update-java-alternatives -s java-8-oracle
java -version
This command should print the version number of Oracle Java 8.
Keep in mind that Oracle Java 8 is no longer supported by Oracle, and it is recommended to use a newer version of Java, such as Java 11 or Java 15. To install a newer version of Java, you can follow the same steps as above, but replace java-8-oracle
with the appropriate version number.
You can also install OpenJDK, the open-source version of Java, using apt-get
. To install OpenJDK 8, run the following command:
sudo apt-get install openjdk-8-jdk
To set OpenJDK 8 as the default Java runtime, run the following command:
sudo update-java-alternatives -s java-1.8.0-openjdk-amd64
To verify that OpenJDK 8 is installed and set as the default, run the java -version
command. This command should print the version number of OpenJDK 8.