1

I'm using WSL2 on Ubuntu 18.04 to run Ruby code in Windows 10. For example, running Ruby on Rails is easily done with no special setup required.

In case of Ruby2D: The installation went fine but, I get an error when running any Ruby2D file, even the most basic one:

require 'ruby2d'
show

I get this error in Console:

error: XDG_RUNTIME_DIR not set in the environment.
Error: (SDL_Init) No available video device
error: XDG_RUNTIME_DIR not set in the environment.
Error: (SDL_CreateWindow) No available video device
Error: (GL2 / SDL_GL_CreateContext) Video subsystem has not been initialized
Error: An OpenGL context could not be created

How do I "add" (or config) a "video device" to my Ubuntu on the WSL2?

4

1 回答 1

3

正如您所注意到的,Windows 10 下的 WSL 没有内置任何 GUI/X/windowing 功能。有几种可能性:

  • 如果您有能力升级到 Windows 11,它支持WSLg(内置)直接在 Windows 上运行 Linux GUI 应用程序。我刚刚安装了 Ruby、ruby2d(及其依赖项)并且能够成功执行您的示例。我认为它只是应该显示一个空白的 GUI 窗口......

如果您无法升级到 Windows 11,仍然有几种可能的替代方案来运行 Linux GUI 应用程序。我没有机会在这种类型的环境中测试 ruby​​2d,但我相信它应该可以工作。如果您遇到问题,我至少可以启动并运行第一个选项来尝试一下,看看我们是否可以解决它:

  • 首先,我的偏好是安装xrdp一个简单的窗口管理器,如xfce. 有关详细信息和说明,请参阅我的答案。您不需要完整的 Gnome 环境(需要 Systemd)——只需简单安装 Xfce 即可。

  • 但是,最流行的方法是在 Windows 10 上安装第三方 X 服务器并DISPLAY手动设置变量。如果您想走这条路,请参阅此问题及其答案以了解详细信息。

于 2021-11-25T01:49:12.240 回答