Install Jstack On Ubuntu May 2026

sudo apt update
sudo apt install openjdk-17-jdk-headless

The -headless version includes jstack, jmap, jstat, etc., but not GUI tools.

jstack --version

If you see a version output, jstack is already installed. If you get command not found, proceed with installation.

For quick reference:

# Step 1: Update apt
sudo apt update

Ubuntu often comes with the JRE pre-installed but not the JDK. First, check if jstack is already available: install jstack on ubuntu

jstack --version

Or simply:

which jstack

If you see output like /usr/bin/jstack, it’s already installed. If you see command not found, proceed with the installation.

With jstack installed, you now have a critical tool for peering into the internals of your Java applications on Ubuntu. sudo apt update sudo apt install openjdk-17-jdk-headless

If you try to run jstack on a Java process running as a different user (for example, if the Java app is running as root or a service user, and you are logged in as ubuntu), you may get an error:

2345: Unable to open socket file: target process not responding or HotSpot VM not loaded

The Fix: You must run jstack with the same user privileges as the running Java process. The -headless version includes jstack , jmap ,

If the Java app is running as Root:

sudo jstack 2345

If the Java app is running as a Service User (e.g., tomcat):

sudo -u tomcat jstack 2345

To use jstack, find the process ID (PID) of the Java process you want to analyze:

ps aux | grep java

Then, run jstack with the PID:

jstack <PID>

This will output the thread stacks of the Java process.

jstack <PID>
Scroll to Top