JAR files are those that have been coded and compiled using the Java programming language. In order to run these files on a Linux system, the Java Runtime Environment (JRE) software must be installed first. This is just a software package that allows the system to understand JAR files, and therefore gives it the ability to open and run them. Usually, the JRE package is not installed on most Linux distros by default, so we must first install Java, and then we can open the JAR file(s).
In this tutorial, we will show you how to install the Java Runtime Environment on all major Linux distributions. This will allow you to open JAR files regardless of what Linux distribution you are using. Then, we will use the newly installed software to open JAR files on Linux, via both command line and GUI.
In this tutorial you will learn:
- How to install the JRE on all major Linux distros
- How to open a JAR file via GUI
- How to open a JAR file via command line
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
How to install JRE on all major Linux distros
The first thing we need to do is install the Java Runtime Environment so that we can open JAR files. You can use the appropriate command below to install the Java JRE with your system’s package manager.
To install the Java JRE on Ubuntu, Debian, Linux Mint, MX Linux, and Kali Linux:
$ sudo apt update $ sudo apt install default-jre
To install the Java JRE on Fedora, CentOS, AlmaLinux, Rocky Linux, and Red Hat:
$ sudo dnf install java-latest-openjdk
To install the Java JRE on Arch Linux and Manjaro:
$ sudo pacman -S jre-openjdk
Run JAR file from command line
Running a JAR file from the command line is very simple. We can use the following syntax:
$ java -jar name-of-app.jar
If the JAR file has a GUI component, it will launch on your screen. Otherwise, text will be output to your terminal.
Run JAR file from GUI
- In your file explorer, navigate to the directory where your JAR file is located. If you cannot run the JAR file by simply double clicking on it, then we will need to tell the system to open this file with the Java JRE that we installed earlier.
- Right click on the file and click on ‘Open with other application.’
- From your list of installed applications, choose the Java runtime environment that we installed earlier.
- Our Java program is now running as expected.
In this tutorial, we saw how to run a JAR file on a Linux system. The only trick here is that we first need to install the Java runtime environment, which has varying instructions depending on the Linux distribution you are using. After installation of the JRE software, we are able to run JAR files from both command line and GUI.