How To Install Java in Ubuntu, Debian and Fedora

Table of Contents

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 multiple versions of Java, 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, as well as different versions of Java. 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 is a pretty robust server environment, with a lot of support for development. 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
				
			

If you want to install another version, just change the version number like so.

				
					sudo apt install openjdk-19-jdk -y
				
			

Now we can confirm what version we are using.

				
					java --version
				
			

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



				
			

Now you just paste in the code to give you a printout.

				
					// Main.java
public class Main
{ 
    public static void main(String[] args) 
    {
         System.out.println("linuxman.co"); 
    }
}
				
			
ubuntu-vim-editor
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
				
			
ubuntu-test-java
Running java program in Ubuntu

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

Debian

With Debian, 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 learn 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 desired version tarball straight from Oracle.

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.

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

If you want to install another version, just change the version number like so.

				
					wget https://download.oracle.com/java/19/latest/jdk-19_linux-x64_bin.tar.gz
				
			
debian-wget-download-jdk-17
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
				
			

Again to reflect another version you must change the numbers.

				
					sudo tar xzvf jdk-19_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

				
			

Now we need to point to it correctly in our path. Next, we need to export add path to the bin.

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

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

Be sure to keep your version numbers straight for exporting paths as well.

				
					export PATH=/usr/lib/jvm/jdk-19.0.2/bin:$PATH
				
			
				
					java --version
				
			
debian-java-version
Java version in debian

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

				
					mkdir test && vim ~/test/Main.java
				
			

Now you just paste in the code to give you a printout.

				
					// Main.java
public class Main
{ 
    public static void main(String[] args) 
    {
         System.out.println("linuxman.co"); 
    }
}
				
			

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
				
			
debian-java-program
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 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. You can use this guide for any system that uses .rpm packages by default. 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
				
			
fedora-install-wget
Installing 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
				
			

If you want to install another version, just change the version number like so.

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

Now we can install the package for the version we chose.

				
					sudo rpm -ivh jdk-17_linux-x64_bin.rpm
				
			

Make sure to reflect the version by changing the numbers.

				
					sudo rpm -ivh jdk-19_linux-x64_bin.rpm
				
			

Next, we can now check our version to confirm we are running the chosen versions of Java

				
					java --version

				
			
jdk-17-version
Java version in fedora

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

				
					mkdir test && vim ~/test/Main.java
				
			

Now you just paste in the code to give you a printout.

				
					// Main.java
public class Main
{ 
    public static void main(String[] args) 
    {
         System.out.println("linuxman.co"); 
    }
}
				
			
debian-vim-editor-1
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
				
			

So, we can see the installation of Java 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. If you want to see an android application build, please leave us a comment. Thanks for reading.

Meet the Author

Leave a Reply