Artificial Intelligence is becoming an integral part of the workflows used by developers, system administrators, and IT professionals. From running large language models (LLMs) to image processing and machine learning experiments, many of the most widely used tools are built primarily for the Linux ecosystem.
Windows users do not have to choose between switching operating systems and running a traditional virtual machine. Windows Subsystem for Linux 2 (WSL2) provides a Linux environment integrated into Windows, complete with a real Linux kernel and close integration with the host operating system. It is particularly useful for development environments, AI frameworks, and—when supported hardware and drivers are available—GPU acceleration.
This guide explains how WSL2 fits into an AI workflow, what advantages it offers, and which tools you can use.
Why choose WSL2 over a traditional virtual machine?
WSL2 uses a lightweight virtual machine managed by Windows, but its day-to-day experience is more tightly integrated than that of a traditional VM. You do not need to manually start and manage a separate machine in the same way as you would with VirtualBox or VMware: your Linux distribution is launched and managed through WSL tools.
| Feature | WSL2 | Traditional virtual machine |
|---|---|---|
| Resource management | Uses host resources and can be configured with resource limits | Requires explicit configuration of virtual CPUs, RAM, and disk |
| Kernel | Real Linux kernel, managed and updated through WSL | Kernel belonging to the operating system installed in the VM |
| Windows integration | Shared access to files, application launching, and integration with Windows tools | Varies; often requires shared folders and additional configuration |
| GPU | Supports GPU compute scenarios, including CUDA on compatible hardware and drivers | Depends on virtualization support and GPU passthrough or sharing features |
| Startup and management | Integrated with Windows and WSL commands | Managed separately through the virtualization software |
This does not mean WSL2 is always faster than every VM, or that it does not use virtualization: WSL2 is itself based on a virtual machine managed by Windows. Its main advantages are integration and operational simplicity. Actual performance depends on the workload, configuration, and location of the files.
An important tip: where to store your projects
For workloads involving many file operations—such as Python package installations, Git repositories, and Node.js projects—it is generally best to keep projects in the Linux filesystem of your WSL2 distribution, for example under ~/projects.
Accessing Windows files through /mnt/c/ is convenient, but workloads that perform many filesystem operations may be less efficient there than in WSL2's native Linux filesystem. You can still access Linux files from Windows File Explorer by entering \\wsl$ or \\wsl.localhost.
WSL1 and WSL2: how the Linux subsystem evolved
The first version of Windows Subsystem for Linux was introduced in 2016 to make it possible to run Linux tools directly on Windows. WSL1 did not include a Linux kernel. Instead, it used a compatibility layer that translated Linux system calls into operations understood by Windows.
This approach was an important step forward, but it had compatibility and performance limitations, particularly with tools that relied on specific Linux kernel features.
In 2019, Microsoft announced WSL2, which is based on a real Linux kernel running in a lightweight virtual machine managed through the Windows virtualization platform. This new architecture improved compatibility with Linux software and made it possible to use tools that depend directly on the kernel, including many container-related workloads.
WSL2 is therefore much more than a terminal emulator: it provides a full Linux environment integrated into the Windows desktop.
Running AI applications and models with WSL2
One of the main reasons to use WSL2 is its compatibility with the AI development ecosystem. Many libraries, applications, and technical guides are designed primarily for Linux. Working in a Linux environment makes it possible to use tools and workflows that are very similar to those used on servers and cloud infrastructure.
Tools that can be used in WSL2 include:
- Ollama, for downloading and running language models locally, subject to available hardware resources.
- PyTorch, a framework used for machine learning and deep learning.
- TensorFlow, a platform for building and training models.
- Docker, for running applications and services in containers.
- Hugging Face Transformers, a library for working with pretrained models and AI pipelines.
Compatibility and performance depend on package versions, drivers, hardware, and each project's installation instructions.
NVIDIA GPUs and CUDA: accelerating AI workloads
GPU acceleration can make a significant difference when running AI models. Tasks such as LLM inference, image processing, and neural network training can benefit from the parallel processing capabilities of GPUs.
On supported Windows systems, WSL2 can expose GPU compute capabilities to the Linux distribution. For NVIDIA graphics cards, this makes it possible to use CUDA in WSL2, provided that the GPU is supported and the Windows driver is compatible with WSL.
Be sure to follow NVIDIA's WSL-specific documentation: in general, you install the Windows NVIDIA driver that includes WSL support, then install the CUDA components required by your tools inside Linux. Do not install a traditional Linux NVIDIA display driver inside WSL, because GPU driver management is handled by the Windows driver.
After setup, the following command can help verify that the GPU is visible from the Linux environment:
nvidia-smi
Whether this command is available and what it reports depend on the driver and configuration. PyTorch, TensorFlow, Ollama, and Docker containers also require versions compatible with the specific GPU platform.
Note: WSL2 does not automatically guarantee that every application can use the GPU. Check the framework requirements, supported CUDA version, and driver compatibility. AMD and Intel GPUs have different setup procedures and support considerations.
Local AI models: Ollama, PyTorch, and TensorFlow
There are two main ways to use AI from WSL2: run models directly on your computer or connect to external services through APIs.
Ollama: running LLMs on your own computer
Ollama makes it easier to download and run language models locally. Once installed according to the official instructions, you can download a model and launch it from the terminal.
For example:
ollama pull llama3.2
ollama run llama3.2
The model shown is an example: availability, size, and requirements vary according to the Ollama version and model catalogue. Before downloading a model, check your RAM, available GPU memory, model weight size, and licence.
Local execution gives you greater control over your data and does not necessarily require sending prompts to a remote service. On the other hand, performance and the size of the models you can run depend on your hardware.
PyTorch and TensorFlow: development and experimentation
Developers building AI applications can use WSL2 as a Python environment for installing PyTorch, TensorFlow, and their dependencies. It is a good idea to create a separate virtual environment for each project to keep library versions isolated.
Example: create and activate a virtual environment.
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
To install PyTorch or TensorFlow with GPU acceleration, select the package and versions specified in the official documentation for your system, GPU, and supported CUDA version. A generic command copied from an outdated guide may install an incompatible build.
Long-context AI models and API gateways: the role of OpenRouter
Not every AI model needs to run locally. When your computer does not have enough memory or processing power, you can use models hosted by external providers through APIs.
A gateway such as OpenRouter provides unified access to models from different providers. An application or script can interact with multiple models without having to integrate each service from scratch.
This is also useful when experimenting with models that offer large context windows or are listed in specific catalogues. Model availability, usage limits, pricing, and free-tier conditions can change, so check each model's listing and provider terms before relying on it in a workflow.
Free and experimental models, and endpoint availability
AI model gateways may list free models, experimental versions, or endpoints that change over time. Names and identifiers of previously available models—such as Space Bunny Alpha or models described as stealth—should not be treated as permanent endpoints.
Before using a model in a script, check:
- whether the model is still listed in the catalogue;
- whether the endpoint or API identifier is correct;
- whether the model is actually free and what limits apply;
- the context window size and any output limits;
- the terms of use, privacy provisions, and data-retention policies.
A model with a very large context window can be useful for analysing long documents, code repositories, or extended conversations. However, a stated context window is not the same as persistent memory: the available context depends on each request and on the application managing it.
Using OpenRouter from the command line
From WSL2, you can interact with an API using standard tools such as curl, Python, or applications compatible with OpenAI-format APIs. Treat your API key like a password: do not put it directly in source code, Git repositories, or screenshots.
A basic curl example:
export OPENROUTER_API_KEY="your_api_key"
curl https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "AVAILABLE_MODEL_ID",
"messages": [
{
"role": "user",
"content": "Briefly explain the advantages of WSL2 for AI development."
}
]
}'
AVAILABLE_MODEL_ID is a placeholder: replace it with the exact identifier of a model listed in the OpenRouter catalogue. Depending on the model and features used, the request may also require additional parameters or headers.
For more reliable use, load the key from an environment variable or a secrets-management system rather than saving it in shared or version-controlled files.
Docker and AI containers on WSL2
Docker is another important component for AI developers. Containers isolate dependencies and services, making it easier to reproduce an environment across different computers.
Docker Desktop can use the WSL2 backend and integrate with one or more Linux distributions. Alternatively, Docker can be configured directly inside the distribution. Follow the official documentation and choose one management approach to avoid conflicts between installations.
For containers that need an NVIDIA GPU, you must also check the NVIDIA Container Toolkit configuration and compatibility between the driver, runtime, and Docker images. Having Docker installed in WSL2 does not automatically enable GPU acceleration.
Hardware resources and limitations to consider
Before choosing a local model, assess your computer's available resources:
- RAM: must be sufficient for the operating system, WSL2, and the running model.
- VRAM: largely determines which models can be loaded fully or partially onto the GPU.
- CPU: remains important for system tasks and inference that is not GPU-accelerated.
- Disk space: models can take up several gigabytes, with additional space needed for caches and dependencies.
- Cooling and power consumption: sustained AI workloads can keep the CPU and GPU under heavy load for extended periods.
There is no universal hardware requirement. A small model used for testing and prototyping may run on an ordinary computer, while larger models or training workloads can require substantial GPU power and memory.
Conclusion: WSL2 as a bridge between Windows, Linux, and AI
WSL2 is a practical solution for anyone who wants to use Linux tools without giving up the Windows desktop environment. Its real Linux kernel, filesystem integration, and ability to use GPU acceleration on compatible configurations make it an interesting environment for developers, data scientists, and AI enthusiasts.
The choice between local models and remote services depends on your goals: tools such as Ollama let you experiment on your own hardware, while API gateways such as OpenRouter provide access to models hosted by different providers. Both approaches can also coexist in the same workflow.
WSL2's greatest advantage is this flexibility: a single Windows computer can become a complete Linux development environment for experimenting with, integrating, and using AI tools, while allowing you to choose where your models run.