We recently migrated our workstations internally from Debian to Arch Linux using Hyprland and Wayland. We were not sure if this experiment would be crowned with success, but we were pleasantly surprised. On top of that, we installed NVIDIA cards, which made the whole procedure even more difficult. But the end result is something to be proud of. The setup runs super stable.
In this context, it is important to be able to continue using any X11 programs, some of which have to run with sudo rights. If this should ever happen to you, here is a guide on how to get these programs running under Wayland:
If you’re running X11 programs under sudo
and want to ensure they use Wayland or XWayland, you need to set the DISPLAY
and XDG_RUNTIME_DIR
environment variables to the correct values. Here’s how to do it:
- DISPLAY Environment Variable: Wayland typically uses
:0
as the display, while XWayland can use:1
or higher, depending on the number of running XWayland sessions.To correctly set theDISPLAY
environment variable for X11 programs, run the following command to determine the display value for your current user:echo $DISPLAY
In most cases, it will be:0
. If you want to use XWayland, it might be something like:1
,:2
, and so on, depending on your configuration. - XDG_RUNTIME_DIR Environment Variable: You should also ensure that the
XDG_RUNTIME_DIR
environment variable is set to the correct value. Wayland requires this variable to access the right resources. You can find out the value ofXDG_RUNTIME_DIR
with the following command: codeecho $XDG_RUNTIME_DIR
Typically, the value ofXDG_RUNTIME_DIR
is set to/run/user/<your user ID>
. Make sure this variable is correctly set.
Now you can run X11 programs with sudo
and set the environment variables accordingly. For example:
bash:
sudo -E DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/<your user ID> your-x11-program
Replace <your user ID>
with your actual user ID and your-x11-program
with the command to run your X11 program.
Using the -E
option with sudo
ensures that environment variables are preserved and not reset to their default values when running sudo
. This is important to ensure that the X11 program receives the correct environment variables.
THANK YOU VERY MUCH… THIS WORKED FOR ME FOR AN INSTALLER THAT NEEDED ACCESS TO AN X SERVER
You are welcome! Glad that this post helped!