How To Install Java 14 On Ubuntu

By bhagwatchouhan
How To Install Java 14 On Ubuntu

This tutorial provides all the steps required to install Java 14 on the popular Linux distribution i.e. Ubuntu. It provides all the steps for Ubuntu 18.04 LTS (Bionic Beaver). The steps should be the same for other versions of Ubuntu, and Linux.


You can also follow the steps to install How To Install VSCode For Java On Ubuntu, How To Install IntelliJ IDEA for Java on Ubuntu, and How To Install Eclipse For Java Development On Ubuntu published by Tutorials24x7. You may also follow the How To Install OpenJDK 14 On Windows to install the latest OpenJDK on Windows and How To Install Java 14 On Windows to install Oracle JDK.


Notes: Make sure that you have gone through the License Agreement for JDK 14.


Download JDK


Open the browser and search for Download JDK 14 or click the link to download from the Oracle website. It will show the JDK download page as shown in Fig 1.


Download Java

Fig 1


Click the download link as highlighted in Fig 1. It will ask to accept the License Agreement and start the download as shown in Fig 2 and Fig 3.


Accept License Agreement

Fig 2


Download Java 14

Fig 3


Install Java


Open the terminal and make directory /usr/java/oracle to keep all the oracle java installations at the same place. We can install multiple versions of Java in this directory. Now copy the downloaded file to this location and extract it as shown below:


>sudo mkdir -p /usr/java/oracle
>cd /usr/java/oracle
>sudo cp /data/setups/jdk-14_linux-x64_bin.tar.gz jdk-14_linux-x64_bin.tar.gz
>sudo tar -xzvf jdk-14_linux-x64_bin.tar.gz


The above steps will install JDK to the path /usr/java/oracle/jdk-14.


Set Environment Variables


In this step, we will configure the environment variable to use the JDK installed by us via the command line.


>sudo nano /etc/profile


Scroll down by pressing Page Down button and add at the end of this file:


# Java 14
JAVA_HOME=/usr/java/oracle/jdk-14 PATH=$PATH:$HOME/bin:$JAVA_HOME/bin export JAVA_HOME export PATH


Now press Ctrl + O and hit Enter to write our change. Press Ctrl + X to exit the nano editor. The nano editor should look like the one shown in Fig. 4.


Java Path

Fig 4


Configure Java Commands


We can configure the Java commands to use the newly installed JDK by default. We can check the installed Java before and after executing these commands as shown below:


# Check version
java -version
# Configure Java Alternatives
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/java/oracle/jdk-14/bin/java" 1
# Configure Javac Alternatives
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/oracle/jdk-14/bin/javac" 1
# Check version
java -version

# Use only in case of multiple JDKs installed

# Configure Java
sudo update-alternatives --config java

# Configure Java Compiler
sudo update-alternatives --config javac


The output of these commands is shown in Fig. 5. We might need to configure active Java if it is previously installed on the system.


Activate Java

Fig 5


These are the basic steps required to install the most recent version of Java on Ubuntu.


Hello World


In this section, we will write our first program in Java using the nano editor.


>sudo mkdir -p /data/programs/java
>cd /data/programs/java
>sudo nano


Now write the first program in Java as shown below, save the program and exit the editor.


// Hello World
public class HelloWorld {
        // The main method
        public static void main( String[] args ) {
                // Print Hello World
                System.out.println( "Hello World !!" );


Use the javac and java to compile and execute the program as shown below.


// Compile the program
sudo javac

// Execute the program
sudo java HelloWorld

// Program output
Hello Java !!


These are the basic steps to write, compile, and execute Java programs.




This tutorial provided all the steps to install Java 14 on Ubuntu 18.04 LTS and also provided the steps to configure it to use from the console. The last section explained the steps to write, compile, and execute the first Java program. You may submit your comments to join the discussion on installing Java 14 on Ubuntu and other Linux systems.

share on :

Profile picture for user bhagwatchouhan