
If you’re using the Windows Subsystem for Linux (WSL) and have encountered the “Cannot connect to display” error, this guide is for you. We’ll walk you through installing an X server on your Windows machine to provide the graphical interface required for your Linux applications.
To fix the "Cannot connect to display" error in Windows 10 Bash, you need to install an X server on your Windows machine and set the DISPLAY
environment variable in your Bash environment. Xming is a recommended X server that you can install, and once it’s running, you should be able to run Linux GUI applications without any issues.
Understanding the Issue
The “Cannot connect to display” error usually arises when you’re trying to run a Linux GUI application without having an X server installed on your Windows machine. An X server is a program that provides a graphical interface for Linux applications to display their graphical output on.
Installing an X Server: Xming
One of the most recommended X servers for Windows is Xming. Here’s how you can install it:
- Download Xming from SourceForge.
- Run the installer and accept the default settings.
- After installation, Xming will automatically launch and run in your system tray. This means it’s ready to receive and display graphical output from your Linux applications.
Setting the DISPLAY Environment Variable
Once Xming is installed and running, you need to set the DISPLAY
environment variable in your Bash environment. This variable tells your Linux applications where to send their graphical output.
Run the following command in your Bash shell:
export DISPLAY=:0
In this command, export
is a Bash built-in command that allows you to set environment variables. DISPLAY
is the name of the environment variable you’re setting, and :0
is the value you’re setting it to. This value is a shorthand for “localhost:0”, which refers to the first display that your X server (in this case, Xming) provides.
Running a Graphical Application
With Xming installed and the DISPLAY
environment variable set, you should now be able to run Linux GUI applications from your Bash shell. For instance, if you’re using Seismic Unix, you could display an image with the following command:
suplane | suximage title="My first test" &
In this command, suplane
generates synthetic seismic data, suximage
displays the data as an image, and &
runs the command in the background so that you can continue using your Bash shell while the image is displayed.
Alternative X Server: MobaXterm
If you’re having trouble with Xming or are looking for a more feature-rich X server, you might want to try MobaXterm. Like Xming, MobaXterm provides an X server that can display graphical output from your Linux applications. However, it also includes a number of additional features, such as a built-in terminal and SSH client.
You can download MobaXterm from its official website.
Conclusion
The “Cannot connect to display” error in Windows 10 Bash can be resolved by installing an X server on your Windows machine and setting the DISPLAY
environment variable in your Bash environment. This guide has shown you how to do this with Xming, but you could also use another X server like MobaXterm if you prefer. With your X server installed and configured, you should be able to run Linux GUI applications from your Bash shell without any issues.
An X server is a program that provides a graphical interface for Linux applications to display their graphical output on. It allows Linux GUI applications to be run and displayed on a Windows machine.
The "Cannot connect to display" error occurs when you try to run a Linux GUI application without having an X server installed on your Windows machine. The application needs the X server to provide the necessary graphical interface.
To install Xming, you can download it from SourceForge and run the installer. Accept the default settings, and Xming will be installed on your Windows machine.
After installing Xming, you need to set the DISPLAY environment variable in your Bash environment. Run the command export DISPLAY=:0
in your Bash shell to set the variable to the first display provided by Xming.
Once Xming is installed and the DISPLAY environment variable is set, you can run Linux GUI applications from your Bash shell. Use the appropriate command for your application, such as suximage
to display an image generated by Seismic Unix.
An alternative X server to Xming is MobaXterm. It also provides an X server that can display graphical output from Linux applications, but it offers additional features such as a built-in terminal and SSH client.
You can download MobaXterm from its official website at https://mobaxterm.mobatek.net/.
Yes, there are other X servers available for Windows. Xming and MobaXterm are commonly recommended, but you can explore other options if you prefer. Just ensure that the X server you choose is compatible with Windows and can provide the necessary graphical interface for Linux applications.