Skip to content

Instantly share code, notes, and snippets.

@Mluckydwyer
Last active April 18, 2026 14:50
Show Gist options
  • Select an option

  • Save Mluckydwyer/8df7782b1a6a040e5d01305222149f3c to your computer and use it in GitHub Desktop.

Select an option

Save Mluckydwyer/8df7782b1a6a040e5d01305222149f3c to your computer and use it in GitHub Desktop.
Install OpenGL on Ubuntu in WSL

How to Install OpenGL in Ubuntu in WSL2

These steps have been tested on Windows 10 with WSL2 running Ubuntu.

1. Dependencies

First install the dependencies:

apt install mesa-utils libglu1-mesa-dev freeglut3-dev mesa-common-dev

There are more than we need, but also include GLut and Glu libraries to link aginst during compilation for application development (these can be removed if that functionality is not required).

2. Window Server

Installing

Then, you will need to setup a window server. Windows 11 should have this built in and work out of the box (skip to step 3). In Windows 10 you will need to install one VcXsrv is a popular option (also known as XLaunch).

Configuration

Once installed, then you will need to make a configuration. You want the following settings:

  • First Screen: Multi-Window, Display=0

  • Second Screen: Start No Client

  • Third Screen: Clipboard=True, Primary Selection=True, Native OpenGL=False, Disable Access Control=True

I recomend you save your configuration file somewhere so that each time you start you window server you can open it instead of rebuilding it. Then start your window server.

WSL Display

Once you have setup and started your Window server, you need to tell Ubuntu/WSL where your display is, we can do this by running the following command:

export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
export LIBGL_ALWAYS_INDIRECT=0

You will need to do this for every new shell you open. Alternatively, you can add this to your .bashrc file to have your shell do it for you an start up.

3. Running a Test

After the following configuration you should be able to run the test application below and see some multi-colored gears spinning:

glxgears
@Kniganiga

Kniganiga commented Jul 15, 2025

Copy link
Copy Markdown

Thank you so much, worked like a charm for me! ❤️
(wsl2, ubuntu 24.04, win 10 22h2)

@AlwinEsch

AlwinEsch commented Apr 18, 2026

Copy link
Copy Markdown

Hi, thanks for this gist!

About "WSL Display", on my computer (maybe on others different and OK) has this not worked.
As solution I found where works on WSL v1 and v2 is to use the IP given on Windows ipconfig.exe (where also listed on ifconfig by v1 only), there his output about

Ethernet-Adapter vEthernet (WSL (Hyper-V firewall)):

   Verbindungsspezifisches DNS-Suffix:
   Verbindungslokale IPv6-Adresse  . : fe80::40fb:183e:e346:188b%70
   IPv4-Adresse  . . . . . . . . . . : 172.27.16.1
   Subnetzmaske  . . . . . . . . . . : 255.255.240.0
   Standardgateway . . . . . . . . . :

EDIT: VcXsrv moved to GitHub: https://github.com/marchaesen/vcxsrv


Here what I found during fault search:

During test I seen following parts:

  1. With /etc/resolv.conf not match in my case:
    Here his output:
~$ cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 192.168.178.1
nameserver fd00::62b5:8dff:fe07:e6ed
nameserver 2003:fd:7706:d900:62b5:8dff:fe07:e6ed
search fritz.box

With ifconfig I checked and brought:

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.56.1  netmask 255.255.255.0  broadcast 192.168.56.255
        inet6 fe80::e103:ee06:d74e:b921  prefixlen 64  scopeid 0xfd<compat,link,site,host>
        ether 0a:00:27:00:00:14  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.27.16.1  netmask 255.255.240.0  broadcast 172.27.31.255
        inet6 fe80::40fb:183e:e346:188b  prefixlen 64  scopeid 0xfd<compat,link,site,host>
        ether 00:15:5d:38:df:77  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Has tried the second IP with export DISPLAY="172.27.16.1:0" and has worked with it.

  1. It seems to make with IP problems by version 2 (wsl.exe --set-version ubuntu 2)
    There brings resolv.conf this:
$ cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 10.255.255.254
search fritz.box

The ifconfig brings there:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1492
        inet 172.27.27.235  netmask 255.255.240.0  broadcast 172.27.31.255
        inet6 fe80::215:5dff:fe3f:3c14  prefixlen 64  scopeid 0x20<link>
        ether 00:15:5d:3f:3c:14  txqueuelen 1000  (Ethernet)
        RX packets 1088  bytes 141015 (141.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1171  bytes 249798 (249.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 15  bytes 1631 (1.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 15  bytes 1631 (1.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

But the IP's 10.255.255.254 and 172.27.27.235 are not usable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment