Install VS Code for Java
Your code editor with built-in Java support
What You’re Installing
VS Code (Visual Studio Code) is a free code editor by Microsoft. With the right extensions, it provides syntax highlighting, error detection, debugging, and Git integration for Java. It is not the same thing as Visual Studio (that’s a different product).
Download and Install
Get it from https://code.visualstudio.com/
Windows
- Download the User Installer (64-bit)
.exe. - Run the installer.
- On the “Select Additional Tasks” screen, check:
- “Add to PATH” (important)
- “Add ‘Open with Code’ action to file context menu” (convenient, optional)
- Finish the installer.
After installing, you can open VS Code from the Start menu or by typing code in a terminal.
macOS
- Download the
.zipfile. - Unzip it (double-click).
- Drag Visual Studio Code.app into your Applications folder.
- Open VS Code, then press
Cmd+Shift+Pand typeShell Command: Install 'code' command in PATH. Run it.
Now you can open VS Code from a terminal with code.
Linux (Ubuntu/Debian)
sudo apt update
sudo apt install -y wget gpg
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -o root -g root -m 644 packages.microsoft.gpg /usr/share/keyrings/
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/vscode stable main" | sudo tee /etc/apt/sources.list.d/vscode.list
sudo apt update
sudo apt install -y code
Or download the .deb package from the VS Code website and install with sudo dpkg -i <file>.deb.
Install the Java Extension Pack
This is required. It gives VS Code the ability to understand Java code.
- Open VS Code.
- Click the Extensions icon in the left sidebar (or press
Ctrl+Shift+X/Cmd+Shift+X). - Search for “Extension Pack for Java” by Microsoft.
- Click Install.
This single pack installs several extensions at once:
- Language Support for Java (syntax, errors, autocomplete)
- Debugger for Java
- Test Runner for Java
- Maven/Gradle for Java
- Project Manager for Java
Wait for all of them to finish installing. You’ll see progress in the bottom-right corner.
Verify JDK Detection
- Press
Ctrl+Shift+P(Windows/Linux) orCmd+Shift+P(macOS) to open the Command Palette. - Type
Java: Configure Java Runtimeand select it. - You should see JDK 25 (Temurin) listed and detected.
If JDK 25 is not listed, VS Code can’t find it. See troubleshooting below.
Test It: Write and Run Hello.java
- Open VS Code.
- Go to File > Open Folder and open any empty folder (e.g.,
~/Documents/java-test/). - Create a new file called
Hello.java. - Paste this code:
public class Hello {
public static void main(String[] args) {
System.out.println("VS Code + Java is working.");
}
}
- Click the Run button (triangle icon) above the
mainmethod, or right-click in the editor and choose Run Java. - You should see
VS Code + Java is working.in the terminal panel at the bottom.
If this works, your setup is correct. You can delete the test folder.
Recommended Settings
Open Settings (Ctrl+, / Cmd+,) and search for these:
- “Auto Save” — set to
afterDelay. Prevents losing unsaved work. - “Format On Save” — enable it. Keeps your code consistently formatted.
- “Terminal: Default Profile” — on Windows, consider setting this to Git Bash or PowerShell.
Common Errors
“JDK 25 not detected” in Java: Configure Java Runtime
VS Code looks for JAVA_HOME or searches common install paths. Fix:
- Open Settings (
Ctrl+,). - Search for
java.jdt.ls.java.home. - Set it to the path of your JDK 25 installation. Examples:
- Windows:
C:\\Program Files\\Eclipse Adoptium\\jdk-25.0.1+12 - macOS:
/Library/Java/JavaVirtualMachines/temurin-25.jdk/Contents/Home - Linux:
/usr/lib/jvm/temurin-25-jdk-amd64
- Windows:
“No Java runtime present, requesting install” (macOS)
This means macOS is using the system stub, not your installed JDK. Make sure JAVA_HOME is set correctly in your shell profile (~/.zshrc or ~/.bashrc). Then restart VS Code.
Extension Pack not working / red squiggles everywhere
- Make sure all extensions in the pack finished installing (check the Extensions panel).
- Try reloading:
Ctrl+Shift+P>Developer: Reload Window. - Check the Java output log:
Ctrl+Shift+P>Java: Open Java Language Server Log.
Run button doesn’t appear above main()
The Java extension hasn’t finished loading yet. Wait 10-15 seconds after opening a .java file for the first time. If it still doesn’t appear, reload the window.
Next Step
VS Code is ready. Next, set up your GitHub account so you can receive and submit assignments.