How to run a graphical application via sudo on sway wayland

Want to start a graphical application from console, using sudo? You might get an error like

Because sudo doesn’t have any display attached to it. Settings the environment variable WAYLAND_DISPLAY fixes the issue

sudo /bin/env WAYLAND_DISPLAY="$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY"  APPLICATIONNAME

replacing APPLICATIONNAME with the application or command you want to execute.

You can also add XDG_RUNTIME_DIR=/… if you want to tell the app where to store temporary files.

sudo /bin/env WAYLAND_DISPLAY="$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY"  XDG_RUNTIME_DIR=/user/run/0 APPLICATIONNAME

So, for completeness, to run the howdy test command

sudo /bin/env WAYLAND_DISPLAY="$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY"  XDG_RUNTIME_DIR=/user/run/0 howdy test

Leave a Comment