

In this section, we will write our first program in Java using the nano editor. These are the basic steps required to install the most recent version of Java on Ubuntu. We might need to configure active Java if it is previously installed on the system. The output of these commands is shown in Fig. # Use only in case of multiple JDKs installed Java HotSpot(TM) 64-Bit Server VM (build 15.0.1+9-18, mixed mode, sharing)

Java(TM) SE Runtime Environment (build 15.0.1+9-18) Sudo update-alternatives -install "/usr/bin/javac" "javac" "/usr/java/oracle/jdk-15.0.1/bin/javac" 1 Sudo update-alternatives -install "/usr/bin/java" "java" "/usr/java/oracle/jdk-15.0.1/bin/java" 1 Sudo apt install openjdk-8-jre-headless # version 8u265-b01-0ubuntu2~20.04 Sudo apt install openjdk-14-jre-headless # version 14.0.1+7-1ubuntu1 Sudo apt install openjdk-13-jre-headless # version 13.0.3+3-1ubuntu2 Sudo apt install default-jre # version 2:1.11-72 We can check the installed Java before and after executing these commands as shown below:Ĭommand 'java' not found, but can be installed with: We can configure the Java commands to use the newly installed JDK by default. The nano editor should look like the one shown in Fig. Now press Ctrl + O and hit Enter to write our change.

Scroll down by pressing Page Down button and add at the end of this file: In this step, we will configure the environment variable to use the JDK installed by us via the command line.

The above steps will install JDK to the path /usr/java/oracle/jdk-15.0.1. # Copy the download to Oracle JDKs directory Now copy the downloaded file to this location and extract it as shown below: We can install multiple versions of Java in this directory. Open the terminal and make directory /usr/java/oracle to keep all the oracle java installations at the same place.
