Skip to content
Related Articles
Open in App
Not now

Related Articles

Compile and Run Java Programs in Sublime Text in Linux

Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 11 Feb, 2021
Improve Article
Save Article

Sublime Text is a free minimalist coding editor developed by Sublime HQ for desktop use. This development and IT program enable you to solely focus on your code, leaving all the other types of eye-candy out.


  1. Open terminal and the specific command are entered there in order to check for the software is there or not. Existence will be displayed out there itself as followed commands.
  2. Configure the sublime text’s builds to run programs
  3. Create a new build system
  4. Save the build System and giving it a run

Step 1: Prior to entering the command, make sure the Java compiler is Installed on the machine. Now open the terminal and enter the command ‘java -version’ which will tell what version of java is installed on the machine. This command is will let us acknowledge the version and assures java is there installed on the machine. 

$ java -version

If java is installed on your machine then you will see openjdk version number in the message as a response along with other info as pictorially been depicted below.

Step 2: Configure the sublime text’s builds to run java programs as if you don’t really want to open sublime text from GUI, just use this command and save yourself some mouse movements.

$ subl <file-name>

Step 3: Create a new build system that follows the two steps. First click on ‘tools → Build System → New Build System’. By far a new file named untitled.sublime-build opens. Lastly, simply copy and paste the following code into that file.

    "shell_cmd": "javac $file_name && java $file_base_name"

The above instruction runs the given command in shell replacing $file_name with your actual file-name and $file_base_name with the file-name without extension( file-name without .java extension) , whenever the code run command ( Ctrl + B ) is invoked in Sublime Text.

Step 4: Save the build System and giving it a run. 

  • First, give it a name like RunJava.sublime-build by hitting ‘Ctrl + S’
  • Open a new java file and write some basic code and save it.

  • Then click Tools→Build System → Choose your newly created build file RunJava (in this case).
  • At last to run the program, press Ctrl + B.

A new window appears at the bottom which shows output of your code. Do remember that this run window can’t take input. It can just show the output of your code. 

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!