Java or NetBeans fails because libXtst.so.6 is missing on Ubuntu
libXtst.so.6 not found when starting a Java GUI program or NetBeansShort answer
libXtst.so.6 comes from the Ubuntu package libxtst6, and a Java desktop program needs it to load. Install libxtst6, or install the full openjdk-21-jre package, which depends on it. A headless Java runtime leaves the library out, which is why servers and minimal images hit this error.
Fix it fast
1Find out which cause you have
Ask the system whether the library is installed and which Java packages are present. An empty answer for the first command means the library is missing.
ldconfig -p | grep libXtst dpkg -l | grep -E 'openjdk|libxtst'2Match what you see, then jump to its fix
What does the error look like?
libXtst.so.6 not found when starting a Java GUI program or NetBeansCan't find/install libXtst.so.6
Cause 1 of 2
The libxtst6 package is not installed
1Check
On Ubuntu 24.04 (amd64) the file /usr/lib/x86_64-linux-gnu/libXtst.so.6 belongs to the package libxtst6, described as the X11 testing record-extension library.
dpkg -L libxtst6 2>&1 | head2Fix
Install the package, then start the program again.
sudo apt update
sudo apt install libxtst63Verify
The library is now known to the loader.
ldconfig -p | grep libXtstConfirmed by packages.ubuntu.com
Cause 2 of 2
Java was installed as a headless runtime, which carries no GUI libraries
1Check
The package openjdk-21-jre depends on openjdk-21-jre-headless and also on libxtst6, libxi6, libxrender1 and other desktop libraries. The headless package alone gives the core runtime without them.
dpkg -l | grep -E 'openjdk-21-jre'2Fix
Install the full runtime on any machine that opens Java windows (a desktop, for example). Keep headless on machines that only run services.
sudo apt install openjdk-21-jre3Verify
Both the runtime and the library are present.
dpkg -l | grep -E 'openjdk-21-jre |libxtst6'
ldconfig -p | grep libXtstConfirmed by packages.ubuntu.com
How do I stop it coming back?
- Use the headless Java package on servers and containers that never show a window, and the full one only where a GUI is needed.
- Install GUI-heavy tools such as NetBeans from a package or installer that declares its dependencies, so apt brings the libraries in.
- Write the libxtst6 line into your provisioning script or Dockerfile once the app needs it.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Servers
Testcontainers (Java) fails with 'docker-machine executable was not found on PATH'
docker-machine executable was not found on PATH
This message is the last step of a search.
3 causes, each with a fixServers
Tomcat logs that the native library for OpenSSL was not found
The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path
This line is a notice, not a crash.
4 causes, each with a fixServers
dnf cannot install MySQL on Amazon Linux 2023
dnf cannot find a mysql-server package on Amazon Linux 2023
Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.
3 causes, each with a fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fix