Install Java Using Apt-Get Command In Ubuntu
If you’re looking for how to install java 8 and 11 using the apt-get command in ubuntu, So you can install it because by default java is not installed. Update the Ubuntu machine using the command apt update
Update the packages in the ubuntu machine. I would suggest only on personal laptops. First, check java is installed or not using java -version.
In order to install it, we have to run these commands. This command will install the Jara Runtime Environment(JRE) and might be your application needs it. so
apt install default-jre
Once it’s done, check the java version.
You may need the Java Development Kit(JDK) to compile the code then run the below command.
apt install default-jdk
Once it’s installed, use this command javac -version
The above commands will install the latest version of Java.
Install Specific Version of Java
we’re installing openjdk8 version using the command apt install openjdk-8-jdk
Once the installation finished. You can set the default java version using the below command.
update-alternatives –config java
I will make java 8 to the default version in ubuntu.
In a similar way, you can install java JDK and JRE version 11 using the below commands.
apt install openjdk-11-jre apt install openjdk-11-jdk
we can also set the javac using update-alternatives –config javac
if you require to set the JAVA_HOME environment variable. Simply use the update-alternatives –config java command to find the path and paste it inside.
vim /etc/environment JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java"
You’re done ubuntu install java 8 11