Skip to main content

Java, that secret sauce you never knew you needed. If you have a smartphone, congratulations, you pray at the Java alter. Not to be confused with JavaScript, many servers and technological infrastructure are built in Java. Java was created way back in 1995 by Oracle. In fact, Google was in a long-standing court battle with Oracle over the use of Java snippets in their products. Today we are here to learn how to install Java 17, to get those servers humming the proper tunes. Why install it on Ubuntu, Debian and Fedora because these represent a large portion of the server community. Putting Java in the hands of those who have that development bug. Definitely the student who requires that home lab to get that grade.

We will discuss the differences between installing Java on these distributions. It is interesting what all Java actually powers, like plugins for this document editor for instance. This writer uses LibreOffice, while also using plugins one may need to install a Java runtime environment, making my workflow much more streamline using LanguageTool. Let’s dive right into it!

Ubuntu

We may as well go in order of the title. Ubuntu 20.04.3 is a pretty robust server environment. Giving you all the underbelly that Debian provides with the butter on top that Canonical builds in. You may want to build an app with high compatibility across platforms. So, the answer to this is you build it in Java first. Let’s get into the process and install the needed packages on Ubuntu.

sudo apt update && sudo apt upgrade -y
sudo apt install openjdk-17-jdk -y
Install java 17 ubuntu

Now we can confirm that we are using version 17.

java --version
Java version in ubuntu

Now you might want to make a nice printout in your terminal just to be sure you have working packages.

mkdir test && vim ~/test/Main.java
public class Main
{
    public static void main(String[] args)
    {
        System.out.println("linuxman.co");
    }
}
Simple java program in ubuntu

Now we can write and quit the file by typing Esc then :wq. Next we can run the code to see if it was a success. Make sure to check your syntax and spelling if you run into any errors.

java ~/test/Main.java
Running java program in Ubuntu

Congratulations, you can now use Java for your coding needs.

Debian

With Debian 11, you will have a very similar experience. You can follow the commands from the last section if you wish. There is no need to add any repository sources, yet we will use a tarball instead. This way we will have the most up to date LTS version straight from Oracle. We will need an additional package called wget to help us download Java. This way, you can see different ways to install packages.

sudo apt update && sudo apt upgrade -y

Next we will install wget in case you don’t have it on your system.

sudo apt install wget

Now we can pull down the tarball straight from Oracle.

wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz
Download java tarball with wget

Now we need to create the directory to extract our tarball to. In this case, we will make it available globally to all users.

sudo mkdir /usr/lib/jvm

We can now extract the tarball.

sudo tar xzvf jdk-17_linux-x64_bin.tar.gz --directory /usr/lib/jvm

To be sure of the path destination, we can us ls to find out the exact version name.

ls /usr/lib/jvm

Our version is jdk-17.0.2, now we can point to it correctly. Next, we need to export add path to the bin.

export PATH=/usr/lib/jvm/jdk-17.0.2/bin:$PATH

We can now check the version of Java we are running to confirm that we were successful.

java --version

Now we can go ahead and write a .java file to see how everything is running.

mkdir test && vim ~/test/Main.java
public class Main
{
    public static void main(String[] args)
    {
        System.out.println("linuxman.co");
    }
}
Simple java program in Debian

Now we can write and quit the file by typing Esc then :wq. Next we can run the code to see if it was a success. Make sure to check your syntax and spelling if you run into any errors.

java ~/test/Main.java
Run java program in Debian

Now we are reinforcing our text printout skills. Once you get the hang of installing the Java runtime environment in Ubuntu or Debian, you really don’t have to work too hard any longer. You have got it covered since they share many aspects. Ubuntu, being a descendant of Debian.

Fedora

Now we are getting into the RHEL area, Fedora 35 has an ecosystem that is very different. You will notice that the package managers are different. The package names are different. We will install the needed packages to build Java from the Oracle .rpm package. You will also have to wget the repository, so we will make sure to install wget as well. Just in case you do not have it on your system. Let’s see what is so different.

sudo dnf update

Now that we have updated the package repositories we can install needed packages.

sudo dnf install dnf-plugins-core -y
sudo dnf install wget
Install wget in fedora

Now that we have what we need, we can pull down the correct .rpm package straight from Oracle.

wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm
Using Wget in fedora

Now we can install the package “jdk-17_linux-x64_bin.rpm”.

sudo rpm -ivh jdk-17_linux-x64_bin.rpm
Install java 17 in fedora

Next, we can now check our version to confirm we are running Java 17.

java --version
Java version in fedora

Now we can make our basic .java program to print out our message.

mkdir test && vim ~/test/Main.java
public class Main
{
    public static void main(String[] args)
    {
        System.out.println("linuxman.co");
    }
}
Simple java program in fedora

Now we can write and quit the file by typing Esc then :wq. Next we can run the code to see if it was a success. Make sure to check your syntax and spelling if you run into any errors.

java ~/test/Main.java
Run simple java program in Fedora

So, we can see the installation of Java 17 does not have to be so scary. Even writing some basic Java can be fun. So get out your new bag of Java tricks, build a server with some real purpose. Knowing Java can really up your game as a programmer, to bring you to the next level. Learning how to use a language such as Java will expose you to lower level syntax. Giving you the confidence to curly brace up that code and get that next Java job. We have now practiced how to print to terminal about 3 times, using different distributions. This showed differences and similarities in all 3 operating systems.

Remember, learning to program is not about learning difficult math, nor do you need any prerequisites. You just need to practice, know how to research, and never give up. You have the power to learn how to make an Android application, or write a program that drives an elevator. If you believe in you, then you have got what it takes. This does not mean you will not fail or feel defeated. After all, testing code is about 75% failure to get you to the 25% everyone sees at the end. The more syntax you expose yourself to, the more you will see the patterns. Unlocking your next step. Thanks for reading!

Leave a Reply