A X server is needed on Windows if you SSH to remote Linux computers and wish to start X or GUI applications from there. It is also necessary if you are working with a Linux distribution running inside Windows Subsystem for Linux (WSL). VcXsrv is a free open-source X server that can be used for all these purposes.
$ export DISPLAY=localhost:0.0
Launch any X or GUI app and its window should now be displayed in its own individual Windows window.
- Remote: Remember to SSH to the remote system with trusted X11 forwarding using option
-Y. On the remote system, set the
$ export DISPLAY=your-windows-ip:0.0
When you start XLaunch you may want to choose to Disable access control. Otherwise you may get errors like this:
Authorization required, but no authorization protocol specified
Error: Can't open display: 10.0.0.99:0.0
Tried with: VcXsrv 22.214.171.124 and Ubuntu 18.04 WSL
Cygwin not only provides most of the Linux programs and shells, it also comes with a builtin X server called Cygwin/X. This is great if you want to run Cygwin GUI applications locally or over SSH from a remote computer.
- Install Cygwin, if you do not already have it.
- Use the Cygwin setup program and install the
xinit packages. The first one is the X server and the second installs a lot of scripts and programs that enable you to start the server and use it.
- Install the
xeyes package. This is a small X application that we will use for testing X.
Use Cygwin/X for local apps
- Kill the
XWin and other X server processes if they are running and close all your Cygwin windows. Open a new Cygwin window.
- Set the
DISPLAY environment variable:
$ export DISPLAY=:0.0
- startx: If you run
startx, you get X server opening a X window with XTerm running inside it. From here on, you can open X apps by running them from that XTerm. You can try by running
xeyes inside that XTerm. Once you kill this X window, your X server is closed.
startxwin: If you run
startxwin, you get X server running, but no windows are displayed. You can now open another Cygwin window and can invoke individual X apps there and they will be displayed in individual windows. You can try by running
xeyes from the Cygwin shell. This is called the multiwindow mode.
Use Cygwin/X for remote apps
- Follow all the steps shown above for local X apps. Make sure you have killed the earlier X server processes, set the
DISPLAY environment variable locally and run
startxwin. Make sure local X apps can display a window to the Cygwin/X server.
- SSH to the remote computer running Linux using ssh on Cygwin or PuTTY. Make sure you have X11 Forwarding enabled for this SSH session. This is usually done by specifying
-X (untrusted forwarding) or
-Y (trusted forwarding) or setting the corresponding X11 Forwarding option in your SSH config file.
- Check the
DISPLAY on the remote computer. It should be set to some value like shown below:
$ echo $DISPLAY
DISPLAY is empty, then either you did not set
DISPLAY locally, did not cleanly restarted a X server locally or there was a problem with SSH X11 Forwarding. Please diagnose.
- Run the
xeyes program from the remote computer. It should display in a window on your local machine. Your Cygwin/X server is working! You can now run GUI/X apps from the remote computer and display them locally. Beware that they will be slow to display and refresh.
Tried with: Cygwin 2.10.0 and Windows 10