The JDK (Java Development Kit) is one of the most important elements of the programming environment. Inside it we can find everything necessary to shape our program, highlighting the binaries necessary to compile, execute and test all the code.
Once the programmer has created the program with the JDK, what we will need is the JRE (Java Runtime Environment). This does not include compilers or other tools used within programming, but rather focuses on distributing the set of utilities and tools necessary for the execution of programs created in this language.
Next, we are going to see how to install the complex package, the JDK, on any Linux distribution in several different ways.
Install OpenJDK on Linux
Although we can find the original Java to install on any Linux distribution, we are going to talk about OpenJDK. What is this? Broadly speaking, it is a free version of the Java JDK. It offers developers and users everything they may need from Java itself, while remaining true to the “Linux philosophy” so characteristic of these systems.
To install it, the first thing we must do is update the list of repositories by executing the following command in a terminal:
sudo apt update
Once this command is executed, the next step will be to see a list with all the packages that we can install from this OpenJDK. To do this, we will execute the following command:
apt list OpenJDK*
As we can see, there are packages for all types of architectures, java versions, demos, development options, etc. In addition, we can also install a global OpenJDK, valid for all versions, and we can even choose if we want to install only the JRE, in case we do not think about programming and want to only run programs.
We can install the standard version of OpenJDK, for a 64-bit system, with the following command:
sudo apt install -a=amd64 openjdk-11-jdk
The “apt” package manager is the most widely used in Linux ecosystems. Distros like Ubuntu, Debian or Mint, to name a few examples, use it. But, in case of using other distros, with other package managers, we can also install the OpenJDK with the corresponding command:
On distros like Fedora:
sudo dnf install java-11-openjdk-devel.x86_64
On Arch Linux:
sudo pacman -S jdk-openjdk
When the installation is finished, we will have Java installed on our Linux. Having installed the OpenJDK, we will have everything we need to create, compile, test and run all kinds of programs created in this programming language. If, on the other hand, instead of the JDK we have installed the JRE, we will only be able to execute the programs, but not create them.
Check the installed Java version
To check that everything is correctly installed on our Linux, we can use a very simple command that will tell us the version of Java that we have installed on the PC. To do this, we simply have to execute the following command in a terminal console:
java -version
By doing so, the java version (or OpenJDK, in our case) that we have on the PC. If this appears to us, it means that this environment has been correctly installed on the computer, and it is ready for us to start working with it. In case it does not appear, then we do not have Java installed on the computer, and we will have to reinstall it.
Uninstall OpenJDK
If we no longer need to use Java on Linux, we can uninstall it to have our system clean, optimized and free of garbage. To do this, what we must do is open a terminal console and execute the following command in it:
sudo apt purge --auto-remove openjdk*
By taking an asterisk to the right of openjdk, we are indicating to the command that what we want is to delete all the packages that correspond to openjdk, thus deleting all the versions that we may have installed at once. Also, if we are advanced users and we only want to delete a specific package, we can remove specific parts by changing “openjdk *” to the specific name of the package we want to delete.
Once the deletion of the data is finished, we can verify that it has been correctly eliminated by executing the command that we already saw in the previous step:
java -version
This will return a message that will tell us that we do not have any Java component installed.