How To Install Java On Ubuntu 20.04 Apr 27, 2020 Raj 4 min read CONTENTS JDK or JRE OpenJDK or Oracle Java Install Java on Ubuntu 20.04 Install OpenJDK Install OpenJDK JDK Install OpenJDK JRE Install Oracle Java Download Oracle Java JDK Install Oracle Java JDK Set Default Java Version Verify Java Version Setup Environmental Variables Conclusion SHARE THIS DOCUMENT IS ALSO AVAILABLE FOR CentOS 8 CentOS 7 CentOS 6 Debian 10 Debian 9 Ubuntu 18.04 Ubuntu 16.04 The Java JDK (Java Development Kit) is a development environment used for developing Java Applications. The Java JDK is a collection of programming tools, such as ass JRE (Java Runtime Environment), Java (Loader for Java Application), Javac (Compiler), Jar (Archiver), etc. JDK or JRE Application developers who are new to Java development often confuse the Java Development Kit with the Java Runtime Environment. The JDK is a collection of tools for developing Java applications, whereas the JRE is for running Java applications. OpenJDK or Oracle Java OpenJDK is an open-source implementation of the Oracle Java SE platform edition. There is no technical difference between OpenJDK and Oracle JDK. Install Java on Ubuntu 20.04 Install OpenJDK or Oracle Java as per your requirement. You can have multiple versions of Java (Both OpenJDK and Oracle Java) on your system. But, you can have only one default version of Java. Install OpenJDK Installing OpenJDK on Ubuntu 20.04 is a pretty straight forward process. First, update the repository index. sudo apt update Install OpenJDK JDK JDK ### Default JDK ie JDK 11 ### sudo apt install -y default-jdk ### Java JDK 11 ### sudo apt install -y openjdk-11-jdk ### Java JDK 8 ### sudo apt install -y openjdk-8-jdk JDK Headless ### Default JDK ie JDK 11 ### sudo apt install -y default-jdk-headless ### Java JDK 11 ### sudo apt install -y openjdk-11-jdk-headless ### Java JDK 8 ### sudo apt install -y openjdk-8-jdk-headless Install OpenJDK JRE JRE ### Default JRE ie JRE 11 ### sudo apt install -y default-jre ### Java JRE 11 ### sudo apt install -y openjdk-11-jre ### Java JRE 8 ### sudo apt install -y openjdk-8-jre JRE Headless ### Default JRE ie JRE 11 ### sudo apt install -y default-jre-headless ### Java JRE 11 ### sudo apt install -y openjdk-11-jre-headless ### Java JRE 8 ### sudo apt install -y openjdk-8-jre-headless Install Oracle Java There is no separate JRE (Java Runtime Environment). Oracle JDK v9.x and above now includes JRE as well. Download Oracle Java JDK You can use either the command line or browser to download the JDK. Go to the Oracle JDK page to download JDK packages using the browser. Download the .deb package for the easy installation. Oracle Java JDK 14: Download Oracle Java 14 (v14.0.1) Oracle Java JDK 11 (LTS): Download Oracle Java 11 LTS (v11.0.7) (Login Required) Oracle Java JDK 8: Download Oracle Java 8 (v8u251) (Login Required) If you still want to download through the command line, install the wget package. sudo apt install -y wget Then, use the wget command to download Oracle Java using the terminal. ### Oracle Java JDK 14 ### wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/14.0.1+7/664493ef4a6946b186ff29eb326336a2/jdk-14.0.1_linux-x64_bin.deb ### Oracle Java JDK 11 ### LOGIN REQUIRED ### Oracle Java JDK 8 ### LOGIN REQUIRED Install Oracle Java JDK Install Oracle Java JDK using the apt command. ### Oracle Java JDK 14 ### sudo apt install -y ./jdk-14.0.1_linux-x64_bin.deb ### Oracle Java JDK 11 (LTS) ### sudo apt install -y ./jdk-11.0.7_linux-x64_bin.deb ### Oracle Java JDK 8 ### sudo tar -zxvf jdk-8u251-linux-x64.tar.gz -C /usr/lib/jvm/ By default,Oracle JDK is installed in /usr/lib/jvm directory when you use the .deb package. Use the update-alternatives command to create a symbolic link for Java with Oracle JDK. Change the Java path depending on the JDK version. sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-14.0.1/bin/java 1 Set Default Java Version Use the update-alternatives command to set the default java version. sudo update-alternatives --config java Select Java: If your system has multiple Java versions, the above command will list all Java versions like below. There are 3 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode * 3 /usr/lib/jvm/jdk-14.0.1/bin/java 1 manual mode Press to keep the current choice[*], or type selection number: 2 Enter the number below selection column to set the default Java version. Here, I chose 2 for OpenJDK 8. Verify Java Version Check the Java version using the following command. java -version Output: openjdk version "1.8.0_252" OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1ubuntu1-b09) OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode) The above output may vary depending upon the version you chose it to be the default Java version. Setup Environmental Variables Java applications often require JAVA environment variables to be set in the system. Create a file under /etc/profile.d directory to place the variables for all users. sudo nano /etc/profile.d/java.sh Change the variables path based on the Java location. export PATH=$PATH:/usr/lib/jvm/java-11-openjdk-amd64/bin/ export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/ export J2SDKDIR=/usr/lib/jvm/java-11-openjdk-amd64/ Load the environments into the current session. source /etc/profile.d/java.sh To set the environment variables for a particular user, place the above variables in ~/.bash_profile file. Conclusion I hope this post helped you install Java on Ubuntu 20.04. Please share your feedback in the comments section. java jdk jre ubuntu-20.04 Prev Post How To Install MariaDB on Ubuntu 20.04 Next Post How To Install Pip On Ubuntu 20.04 RELATED POSTS How To Upgrade To Ubuntu 20.04 From Ubuntu 18.04 / Ubuntu 19.10 [Detailed Guide] How To Install MariaDB on Ubuntu 20.04 How To Install Ubuntu 20.04 Alongside With Windows 10 in Dual Boot How To Install Linux, Nginx, MariaDB, PHP (LEMP Stack) in Ubuntu 20.04 Ubuntu 20.04 LTS Released - New Features & Download Links How To Install Ubuntu 20.04 LTS (Focal Fossa) On UEFI and Legacy BIOS System Please enable JavaScript to view the comments powered by Disqus. comments powered by Disqus RECENT POSTS How To Install VirtualBox On Linux Mint 20 How To Backup and Restore Ubuntu & Linux Mint With Timeshift How To Upgrade To Linux Mint 20 From Linux Mint 19 [Detailed Guide] How To Install KVM On Ubuntu 20.04 / Linux Mint 20 How To Install Plex Media Server On Ubuntu 20.04 / Linux Mint 20 How To Install Android Studio on Ubuntu 20.04 TOP POSTS Install xrdp on CentOS 7 / RHEL 7 Install Gnome GUI on CentOS 7 / RHEL 7 Change default network name (ens33) to old “eth0” on Ubuntu… Install μTorrent (uTorrent) on Ubuntu 14.04 How To Configure High-Availability Cluster on CentOS 7 /… How To Install and Configure VNC Server in CentOS 7 / RHEL 7