If you install any package having the .jar extension and try to execute it, it may throw an error saying "The file is not marked as executable":
And in this tutorial, I will walk you through how you can install its prerequisites and run Jar files in Ubuntu and other Linux with multiple methods.
Run jar files in Ubuntu
If you don't know, JAR stands for Java ARchive so you must have a working Java environment.
If you have Java installed, you should be able to run it. Check if Java is installed with:
java --version
If you see an error instead of the version number, install Java runtime environment using the following command:
sudo apt install default-jre
Once you're done with installing the prerequisite, you can follow any of the two given methods to run jar files:
- Using GUI
- Using the terminal
So let's start with the first one.
Method 1: Using GUI
The first step is to open the file manager from the system menu and navigate to the jar file which you want to run.
Then, right-click on the jar app and select Properties
.
From there, select Permissions
and enable Allow executing file as program
:
That made the file executable.
But you have yet to select which app it should use to run the jar files.
To select an Application to start the jar files, again, click on the jar file and choose the second option Open with Other Application
and choose the OpenJDK Java Runtime option:
That's it.
Now, you can start the jar application like you do with any other files by pressing the Enter key.
In my case, it was an installer and it started as it should:
Method 2: Using the Terminal
If you believe in efficiency, I'm about to show you the terminal method will complete the task in only three commands.
First, open the terminal and navigate to the directory where the jar file is located using the cd command:
cd /path/to/jar_file
Once done, use the chmod command with the +x
flag to make the file executable:
chmod +x Filename.jar
And finally, you can use the Java command with the -jar
flag to run the jar file:
java -jar Filename.jar
That's it!
Here's how to set up the JAVA_HOME variable
Most of the users set the JAVA_HOME variable incorrectly. So we thought, why not make a dedicated guide to get things done correctly?
Here's how you set up the JAVA_HOME variable correctly:
I hope you will find this guide helpful.