Software & AppsOperating SystemLinux

How To Fix “Cannot Connect to Display” Error in Windows 10 Bash

Ubuntu 10

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.

Quick Answer

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:

  1. Download Xming from SourceForge.
  2. Run the installer and accept the default settings.
  3. 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.

What is an X server?

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.

Why am I getting the “Cannot connect to display” error?

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.

How do I install Xming?

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.

How do I set the DISPLAY environment variable?

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.

How can I run a graphical application after installing 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.

What is an alternative X server to Xming?

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.

Where can I download MobaXterm?

You can download MobaXterm from its official website at https://mobaxterm.mobatek.net/.

Can I use any other X server instead of Xming or MobaXterm?

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.

Leave a Comment

Your email address will not be published. Required fields are marked *