Matheus Almeida's iconMatheusAlmeida

Installing JDK on Linux

First, run the following command in the terminal:

sudo apt update
sudo apt update

The sudo apt updatesudo apt update command updates the system repository with the latest packages.

To install JDK version 17, run the command:

sudo apt install openjdk-17-jdk
sudo apt install openjdk-17-jdk

Now, we must set the JAVA_HOMEJAVA_HOME environment variable. This will allow us to use JDK tools.

First, we need to know the JDK installation path running the command:

sudo update-alternatives --config java
sudo update-alternatives --config java

The next step is to copy the path shown in the terminal and run:

export JAVA_HOME=/path/shown/in/the/terminal
export JAVA_HOME=/path/shown/in/the/terminal

To make sure everything went well, we can check the javacjavac and javajava version running:

javac -version
java -version
javac -version
java -version

javacjavac is the compiler/command responsible for converting Java source code into Java bytecode.

Java source code is the classes and interfaces inside .java.java files and bytecode is the JVM native code.

Difference between JVM, JRE, and JDK

JVM stands for Java Virtual Machine.

JRE stands for Java Runtime Environment.

JDK stands for Java Development Kit.

JVM and JRE execute bytecode.

JDK lets you write in Java, compile, and execute the bytecode.

JDK = JRE + developer tools.

JRE = JVM + libraries.