Skip to main content

wslenv

wslenv is a small helper script intended to populate and print environment variables that are useful when running inside WSL (Windows Subsystem for Linux) - especially when those variables are missing.

It detects WSL, prepares distro info, configures interop, and merges the Windows PATH. Optionally, it prepares WSLg-related GUI variables.

At the end, it prints shell-ready export commands for any variables it had to set.

Rationale

Why you need it There are situations where you end up inside a WSL distribution without the expected interop variables. For example:

  • Log into it via SSH. I.e. you have in your ~/.ssh/config:
    Host wsldistr-inside-winhost
      ProxyCommand ssh winhost wsl -d wsldistr -u root sshd -i
    
  • After sudo -H -i.

Installation

If you want it only as a program available in your PATH, use pipx:

pipx install wslenv

If you want to have development version:

$ git clone https://github.com/pyhedgehog/wslenv.git
$ cd wslenv
$ pipx install -e .

Usage

# wslen --help
usage: wslenv [-h] [--no-gui] [--unset]

Script to investigate environment variables useful in WSL if missing.

options:
  -h, --help            show this help message and exit
  --no-gui, --no-wslg, --plain, -p
                        Skip WSLg variables.
  --unset, -u           Unset WSL/WSLg variables.

Varibles: PATH, WSL_DISTRO_NAME, WSL_INTEROP, WSLENV, *(vars from WSLENV);
WSLg variables: DISPLAY, PULSE_SERVER, WAYLAND_DISPLAY, WSL2_GUI_APPS_ENABLED, XDG_RUNTIME_DIR

Typical usage is to evaluate wslenv output in your shell or in your script (i.e. in ~/.profile:

eval "$(wslenv)"

If you want to skip WSLg variables:

eval "$(wslenv --no-gui)"

If you want to unset WSLg variables (keeping WSL variables):

eval "$(wslenv --unset --no-gui)"

If you want to unset all WSL variables:

eval "$(wslenv --unset)"

What it sets

Core WSL variables

  • WSL_INTEROP - detects the nearest parent WSL interop relay
  • WSL_DISTRO_NAME - uses wslpath -w /
  • WSLENV - gets Windows WSLENV or sets it to empty
  • PATH - merges Windows PATH entries into the Linux PATH (avoids duplicates)

Also variables mentioned in WSLENV can be set.

Optional WSLg variables (GUI apps)

When GUI support is detected and --no-gui / --no-wslg is not used:

  • WAYLAND_DISPLAY
  • PULSE_SERVER
  • XDG_RUNTIME_DIR
  • DISPLAY
  • WSL2_GUI_APPS_ENABLED

Notes

The script relies on WSL interop utilities:

  • wslpath -m /
  • wslinfo --msal-proxy-path
  • cmd.exe /c set

There are some corner cases:

  1. All variables processed by wslenv and wsl itself can has different result. Normal wsl startup procedure first sets wsl-specific variables and the processes shell's profile. But when you use eval $(wslenv) (even in .bashrc) you already has initial setup done.
  2. Any wsl-specific variable (including mentioned in $WSLENV) set by wslenv only if it not set from some other source.
  3. $PATH and */l variables mentioned in $WSLENV processed differently - paths from windows %Path% added to $PATH, but variables from WSLENV defined only if they are not already defined in current environment.

Roadmap

  • Run command in modified environment (like wslenv -c cmd.exe /c echo %PATH%).
  • Check in fresh wslc.exe containers.
  • Make OS packages (at least for Alpine and Ubuntu as sane and default WSL distributions).
  • Detect WSL kernel version and process corner cases if found.
  • Make minimal version - i.e. without python dependencies (shell or compilable - C/Ninja/Rust/codon/...).
  • Plugins? No idea what for. :-(

Help wanted

Changelog

0.2.0 (2026-09-01)

  • Support for unsetting variables using wslenv -u.
  • Import from Windows variables mentioned in inherited or imported WSLENV.

0.1.0 (2026-07-28)

  • Initial release to github and pypi.
  • Make mypy/pyrefly happy.

0.0.0 (2026-07-20)

  • Never released.
  • First usable code.

Release files for wslenv 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wslenv 0.2.0
File Size Uploaded
wslenv-0.2.0.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wslenv 0.2.0
File Interpreter ABI Platform
wslenv-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.2 kB

Release files / wslenv-0.2.0.tar.gz

Download URL wslenv-0.2.0.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
352ee46ecc01ca8c82505b639dc2f4ef4aae8da26b18283bfbef90f60f5527e5
BLAKE2b-256 checksum
How to use checksums
8da7fa43f749ebfd777d61f9327343060d54550e3571e43037ba09e86bbc08d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.4 CPython/3.12.10 Windows/10

Release files / wslenv-0.2.0-py3-none-any.whl

Download URL wslenv-0.2.0-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
deb1523b8c7f784c9c9dee4441a05fabd99aedff1cf319c7b819cfc83f97b070
BLAKE2b-256 checksum
How to use checksums
64ffaf4cdc9a9545a6756588bf2ab36b479ad7abba0e120d7e4e2aa5a000e9d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.4 CPython/3.12.10 Windows/10

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page