I have a Raspberry Pi with Raspbian Stretch Lite. I want do execute only some single graphical programs remotely and do not want to install a complete graphical user interface with a Desktop program only to be able to use VNC. I know X Window can do it.

How do I have to setup X Window to run single graphical programs on the RasPi but shown remotely on my Laptop?


To run graphical X-programs remotely you first need a PC with an X Window system. I use my Laptop with a Debian Stretch installation and a Xfce Desktop.

On Wikipedia - X Window System you will find:

Unlike most earlier display protocols, X was specifically designed to be used over network connections rather than on an integral or attached display device. X features network transparency, which means an X program running on a computer somewhere on a network (such as the Internet) can display its user interface on an X server running on some other computer on the network. The X server is typically the provider of graphics resources and keyboard/mouse events to X clients, meaning that the X server is usually running on the computer in front of a human user, while the X client applications run anywhere on the network and communicate with the user's computer to request the rendering of graphics content and receive events from input devices including keyboards and mice. The fact that the term "server" is applied to the software in front of the user is often surprising to users accustomed to their programs being clients to services on remote computers.

So first the X server should be able to display local X programs (X clients) like a graphical desktop, firefox and any other local graphical programs. That's usually the case. Now it is only one little step to get the display of remote running X programs (X clients).

On my RasPi with Raspbian Stretch Lite without any graphical user interface I installed some small X test programs:

rpi ~$ sudo apt install x11-apps

Some of this nice little programs are xeyes or xclock. On my Laptop I can now start:

laptop ~$ ssh -X pi@ xeyes

and see the eyes following the cursor on the laptop. If you start xclock you will see the time on the RasPi. It's now up to you to install the X programs you need. For example a file manager would be nice to manage the files on the RasPi from your Laptop. The default file manager of Xfce is thunar. A generic lightweight X11 file manager is Xfe. But this programs will install many more additional libraries than the simple x11-apps.


To add to @Ingo's answer: If your laptop (or desktop for that matter) happens to be a mac, you can use XQuartz as your X11 app. Apple used to include X with macos, but ceased doing so in v 10.5. To fill the void, Apple created the XQuartz project, and development continues through its GitHub site.

Installation is easy via the .dmg file available for download. And setup is reasonably straightforward. I use it over an SSH connection to my RPi as follows:

$ ssh -Y pi@raspberrypi3b.local

where raspberrypi3b is simply the host name of my (headless) RPi, and the -Y option instructs the SSH server to forward X over the SSH connection to my mac. Once the SSH connection is made, I just start XQuartz on my mac, get a terminal window, and launch Idle from the command line. The only issue I encountered was with the ~/.Xauthority file on the RPi. I eventually learned that this file is automatically generated, so don't let the error messages put you off when it doesn't work immediately after installation. I'm currently on macos 10.14.4, and XQuartz works fine, but I do wonder how it will fare in the next major release of macos given Apple's frequent warnings about "non-compliant" apps that won't be supported in some (unspecified) future release.

I personally have only limited use for XQuartz: to run Idle for Python development on my RPi. However, there are apparently quite a few X11 apps available for the RPi if you're into that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.