To compile the file, open your terminal and type

javac filename.java

To run the generated class file, use

java filename

But to do this you need to have the Java JDK installed in your computer. You can install it with the instructions in How do I install Java?.

Answer from Raja G on askubuntu.com
🌐
Oracle
java.com › en › download › help › linux_x64_install.html
Linux 64-bit installation instructions for Java
Note about root access: To install Java in a system-wide location such as /usr/local, you must login as the root user to gain the necessary permissions. If you do not have root access, install Java in your home directory or a subdirectory for which you have write permissions. Change to the directory in which you want to install. Type: cd directory_path_name For example, to install the software in the /usr/java/ directory, Type: cd /usr/java/ Move the .tar.gz archive binary to the current directory. Unpack the tarball and install Java tar zxvf jre-8u73-linux-x64.tar.gz The Java files are installed in a directory called jre1.8.0_73 in the current directory.
🌐
Princeton CS
introcs.cs.princeton.edu › java › linux
Hello World in Java on Linux
August 14, 2019 - This document instructs you on how to setup a Java programming environment under Linux. It also provides a step-by-step guide for creating, compiling, and executing your first Java program using either DrJava or the command line. We assume some familiarity with the command line. All of the software is freely available on the web. You will use ...
Discussions

Why is Java considered more of a "first class citizen" in the Linux world compared to .NET/Mono?
Linux might treat .NET as a "first class citizen" when .NET treats Linux as a "first class citizen". The full runtime and standard libraries are available for Linux and are open source (not just core) Developer Studio runs on Windows Desktop applications created with Visual Studio work equally as well on Linux. And in any other way that Linux might be locked out of the .NET world. I consider Mono hard-linked to the .NET world, so I can't really put it on an island and think of it or treat it completely differently. (edit:typo) More on reddit.com
🌐 r/linux
317
256
December 3, 2023
Creating java apps for linux
Java is my programming language of choice and was thinking about how I would deploy a java project to linux machine. Assuming I create a release jar and package it into a .tar.gz for users to easily download, how would I create a binary in /usr/bin (or atleast thats where I think it would go) ... More on reddit.com
🌐 r/linuxquestions
6
4
July 6, 2021
Does Minecraft Java Edition run on Linux?

Java runs on linux, and minecraft java edition does as well.

You can also run bedrock on linux. Using this: https://github.com/ChristopherHX/mcpelauncher-manifest

I bought bedrock on my (android) phone and use that to run it on my PC.

More on reddit.com
🌐 r/Minecraft
8
4
April 6, 2020
Need a way to run Java applets on the current version of Firefox

Java's not really part of the web, and Java's plugin support has been deprecated and removed from both the browser's and Oracle's sides. (The plugin module NPAPI itself is on its way out of the browser, not just for Java)

If you really need to run a java applet, you should use the standalone Java Web Start, javapackager, or JavaFX/WebView tools, not an outdated version of a browser that happens to still support Java: https://www.infoq.com/news/2017/02/oracle-java-browser-applet/

More on reddit.com
🌐 r/firefox
10
0
January 4, 2020
🌐
Opensource.com
opensource.com › article › 19 › 11 › install-java-linux
How to install Java on Linux | Opensource.com
If you download an RPM or DEB file from Azul.com, then you can use your package manager to install it. For Fedora, CentOS, RHEL, and similar, download the RPM and install it using DNF: ... For Debian, Ubuntu, Pop_OS, and similar distributions, download the DEB package and install it using Apt: ... Java is now installed. Some applications are developed for a specific version of Java and don't work with any other version. This is rare, but it does happen, and on Linux, you can use either the local install method (see Installing Java from a TAR file) or the alternatives application to deal with this conflict.
🌐
It's FOSS
itsfoss.com › run-java-program-ubuntu
How to Run Java Programs in Ubuntu
January 11, 2023 - You’ll be asked to enter your account’s password. When you type the password, nothing is seen on the screen. That is normal. Just enter your password blindly. When asked, press the enter key or Y key. Installing JDK that also contains the Java compiler · The above command should work for other Debian and Ubuntu based distributions like Linux Mint, elementary OS etc. For other distributions, use ...
🌐
Dracula Servers
draculaservers.com › home › how to run java programs in linux terminal?
How to Run Java Programs in Linux Terminal? - Dracula Servers Tutorials
June 30, 2024 - Once that is done, open a terminal and head to the directory of the JAR file. Then run the command “java -jar [filename].jar” · The main difference in running Java Programs and Java Applications (JAR files) is adding the “-jar” flag.
Find elsewhere
🌐
Wikihow
wikihow.com › computers and electronics › operating systems › linux › 4 ways to install java on linux - wikihow
4 Ways to Install Java on Linux - wikiHow
May 1, 2026 - Oracle Java is no longer supported on Ubuntu. Use OpenJDK instead (free implementation of Oracle Java). ... Oracle doesn't distribute .deb packages, any and all .deb packages for Oracle's Java is from a 3rd party and can cause harm to your system. ... This article was written by Ethan Stout and by wikiHow staff writer, Jack Lloyd. Ethan Stout is a Linux ...
🌐
LinuxVox
linuxvox.com › blog › java-linux
Java on Linux: A Comprehensive Guide — linuxvox.com
To compile and run this program on Linux, follow these steps: # Compile the Java program javac HelloWorld.java # Run the compiled Java program java HelloWorld · When working on larger Java projects, you may use build tools like Maven or Gradle.
🌐
LinuxForDevices
linuxfordevices.com › home › how to run a command-line java program on linux?
How to Run a Command-Line Java Program on Linux? - LinuxForDevices
July 19, 2021 - In this tutorial, we will learn about how to run a command-line Java program from the Linux terminal. To run Java programs from the command line, a functional Java Runtime Environment is required.
🌐
Yolinux
yolinux.com › TUTORIALS › LinuxTutorialJava.html
YoLinux Tutorial: Java on Linux
It is then often common to generate soft links to wherever the JDK resides. Eg when using the RHEL OpenJDK: ln -s /usr/lib/jvm/java-1.7.0-openjdk.x86_64/jre /opt/java/latest · There is a choice of running 32 bit Java on a 32 bit or 64 bit Linux platform or running 64 bit Java on a 64 Linux bit platform.
🌐
DEV Community
dev.to › mtendekuyokwa19 › setting-up-for-java-on-linux-133f
Setting Up for Java on Linux. - DEV Community
February 14, 2024 - To get started I will have to explain the two main components you need to have Java up and running on your machine. You will need the Java development kit (JDK) and an IDE. Yes, Just those two (does a backflip celebration).
🌐
LinuxVox
linuxvox.com › blog › java-en-linux
Java and Linux: A Comprehensive Guide — linuxvox.com
Environment variables are used to configure the Java runtime environment. The most important ones are JAVA_HOME and PATH. To set JAVA_HOME permanently on Linux, you can add the following lines to your .bashrc or .bash_profile file:
🌐
The Knowledge Academy
theknowledgeacademy.com › blog › install-java-linux
How to Install Java on Linux: Step By Step Installation Guide
April 23, 2026 - Step 8: To verify the value of the JAVA_HOME variable, you can use the command echo $JAVA_HOME. This command will display the location of your Java installation on the terminal. It will show the path you just set as an output, which signifies that you have correctly set the environment variable. /usr/lib/jvm/java-11-openjdk-amd64/bin/java · Now, your Linux machine is ready to develop and run Java applications.
🌐
Princeton
lift.cs.princeton.edu › java › linux
Hello World in Java (Linux)
This document instructs you on how to set up a Java programming environment for your Linux computer. It also provides a step-by-step guide for creating and compiling a Java program in IntelliJ and executing it from the command line. You will need a 64-bit version of Linux (such as Ubuntu, Fedora, or Debian) with root privileges. You will use ...
🌐
LabEx
labex.io › tutorials › java-how-to-set-up-java-on-linux-system-514717
How to set up Java on Linux system | LabEx
Learn how to install and configure Java Development Kit (JDK) on Linux, covering essential steps for setting up a robust Java development environment with easy-to-follow instructions.
🌐
ArchWiki
wiki.archlinux.org › title › Java
Java - ArchWiki
May 15, 2026 - Several other Java environments are available in Arch User Repository but are not officially supported. ... Arch Linux officially supports the OpenJDK implementations only. After installation, the Java environment will need to be recognized by the shell ($PATH variable).
🌐
FOSS Linux
fosslinux.com › home › programming › compile and run java from the linux cli (2026 developer guide)
How to Compile and Run Java from Command-line in Linux
April 29, 2026 - To compile a Java program that references code within that JAR file, you must include it in your compilation command: fosslinux@dev:~$ javac -cp ".:external_libs/utilities.jar" Main.java · The -cp flag defines the classpath. The dot (.) represents the current directory, and the colon (:) separates multiple paths on Linux. Windows uses a semicolon, which is a common source of cross-platform confusion.
🌐
Oracle
java.com › en › download › help › linux_install.html
How do I download and install 32-bit Java for Linux?
Install the package. rpm -ivh jre-8u73-linux-i586.rpm To upgrade a package, rpm -Uvh jre-8u73-linux-i586.rpm · Exit the root shell. No need to reboot. Delete the .rpm file if you want to save disk space. The installation is now complete. Go to the Enable and Configure section. When you install the Java platform, the Java plugin file is included as part of that install. If you want to use Java within Firefox, you need to manually create a symbolic link from the plugin file in the release to one of the locations that Firefox expects.
🌐
Oracle
java.com › en › download › help › enable_console_linux.html
How do I enable and view the Java Console for Linux or Solaris?
The Java Console provides information about the Java version, user home directory, and any error message that occurs while running an applet or application. You can enable the Java Console for the Linux and Solaris platforms through the Java Control Panel · Open a Terminal window. Go to the ...