There are two standard types of installation available are JDK and JRE. JDK (Java Development Kit) provides the ability to develop new Java application, which includes Java compiler. JRE (Java Runtime Environment) provides the runtime environment for any Java application with applets. The Java developers required to install JDK and JRE both on their system to create new Java Applications.
Use this tutorial to Install Java 8 on Ubuntu 18.04, 17.10, 16.04, 14.04 and 12.04 LTS and LinuxMint 18, 17 using PPA. Follow the below steps to Install Java on Ubuntu command line.
Step 1 – Install Java 8 on Ubuntu
You need to enable additional repository to your system to install Java 8 on Ubuntu VPS. After that install Oracle Java 8 on an Ubuntu system using apt-get. This repository contains package named oracle-java8-installer, Which is not an actual Java package. Instead of that, this package contains a script to install Java on Ubuntu.
Run below commands to install Java 8 on Ubuntu and LinuxMint.
sudo add-apt-repositoryppa:webupd8team/java sudo apt-getupdate sudo apt-getinstall oracle-java8-installer
Step 2 – Verify Java Inatallation
The apt repository also provides package oracle-java8-set-default to set Java 8 as your default Java version. This package will be installed along with Java installation. To make sure run below command.
sudo apt-get installoracle-java8-set-default
After successfully installing Oracle Java 8 using the above steps, Let’s verify the installed version using the following command.
java -versionjava version " 1.8.0_161" Java(TM) SE Runtime Environment (build 1.8.0_161-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
Step 3 – Setup JAVA_HOME and JRE_HOME Variable
After installing Java on Linux system, You must have to set JAVA_HOME and JRE_HOME environment variables. Which is used by many Java applications to find Java libraries during runtime. You can set these variables in /etc/environment file using the following command.
cat >> /etc/environment <<EOL JAVA_HOME=/usr/lib/jvm/java-8-oracle JRE_HOME=/usr/lib/jvm/java-8-oracle/jre EOL
All done, you have successfully installed Java 8 on a Linux system. You may also need to install Tomcat server to run your Java web application. Use our another tutorial to Install Tomcat 7 or Install Tomcat 8 or Install Tomcat 9 on Ubuntu, Debian, and LinuxMint systems.