-
Notifications
You must be signed in to change notification settings - Fork 0
Setting Up WSL (Windows Subsystem for Linux) to Run Your First .NET Console App
A start-to-finish guide: from a fresh Windows machine to running a "Hello World" C# console app inside Linux (WSL2 + Ubuntu). Written for Windows 11.
WSL (Windows Subsystem for Linux) lets you run a real Linux environment inside Windows — no separate virtual machine to manage. This guide installs WSL2 with Ubuntu, installs the .NET SDK inside it, and runs a console app on Linux.
The whole path:
- Install the WSL engine
- Install an Ubuntu distribution
- Create your Linux user
- Install the .NET SDK (user-level, no sudo)
- Make
dotnetpermanent on your PATH - Build and run a Hello World app
Open PowerShell or Windows Terminal as Administrator (right-click → "Run as administrator"), then run:
wsl --installThis enables the WSL2 platform. On some systems it also installs Ubuntu automatically; on others it only installs the engine. Restart your computer when it finishes.
Tip: After restart, verify the engine with
wsl --status. If it reportsDefault Version: 2, the engine is ready.
Check whether a distro is already installed:
wsl --list --verboseIf it says "has no installed distributions", install Ubuntu. See available options first:
wsl --list --onlineThen install the latest LTS (recommended — stable and well-supported for .NET):
wsl --install -d Ubuntu-24.04Why Ubuntu LTS? Microsoft officially tests .NET against it, package support is excellent, and online help is abundant. Pick an LTS version (e.g. 24.04) over the newest release for fewer surprises.
The first time Ubuntu launches, it provisions itself and prompts:
Create a default Unix user account: <type a username>
New password: <type a password — INVISIBLE as you type>
Retype new password:
Important gotchas:
- After typing the username, press Enter — it waits for input, it is not frozen.
- The password is completely invisible while typing — no dots, no asterisks. This is normal Linux behavior, not a hang. Type it and press Enter.
- This Linux username/password is separate from your Windows login. It does
not replace or affect how you sign in to Windows. The password is mainly used
for
sudo(admin commands).
When done, you land at a Linux prompt like you@machine:~$. Ubuntu is now live.
The .NET on Windows and the .NET on Linux are different binaries. To run apps on Linux you must install .NET inside Ubuntu, separately.
The cleanest method is Microsoft's install script — it installs into your home
folder (~/.dotnet) and requires no sudo.
Inside the Ubuntu terminal:
cd ~
wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
chmod +x dotnet-install.sh
./dotnet-install.sh --channel LTSThis downloads ~200 MB and installs the latest LTS SDK to ~/.dotnet.
Avoid
sudo apt install dotnetorsudo snap install dotnetfor this setup. Those may install a different/older version and cause confusion. Stick with the script-installed SDK in~/.dotnet.
The installer only adds dotnet to PATH for that one session. Make it permanent
by adding it to ~/.bashrc:
cat >> ~/.bashrc <<'EOF'
export DOTNET_ROOT=$HOME/.dotnet
export PATH=$PATH:$HOME/.dotnet:$HOME/.dotnet/tools
EOFThen reload it in your current shell:
source ~/.bashrcCommon trap: If you skip
source ~/.bashrc(or use a terminal that was already open before this step), you'll getCommand 'dotnet' not found. Either runsource ~/.bashrc, or simply close and reopen the Ubuntu terminal — a new shell reads.bashrcfrom the start.
Verify it works:
dotnet --version
dotnet --list-sdksYou should see a version number (e.g. 10.0.300) and the SDK path under
~/.dotnet/sdk.
Create a project in your Linux home folder (fast native filesystem):
cd ~
mkdir hello && cd hello
dotnet new console -o .Replace Program.cs with a simple app:
cat > Program.cs <<'EOF'
Console.WriteLine("Hello World");
Console.WriteLine("Press any key to exit this console app...");
Console.ReadKey();
EOFBuild and run it:
dotnet run -c ReleaseYou'll see:
Hello World
Press any key to exit this console app...
Press any key, and it exits. Your C# app just ran on Linux. 🎉
WSL gives you two filesystems:
-
Linux native (
~, i.e./home/<user>) — fast. Best for active development. Physically stored in WSL's own virtual disk (a.vhdxfile on your C: drive). -
Windows drives — mounted inside Linux at
/mnt/c,/mnt/d, etc. Shared with Windows, but slower to access from the Linux side due to the filesystem-boundary overhead.
A Windows path like D:\Projects\MyApp becomes /mnt/d/Projects/MyApp in Linux.
For quick tests you can run straight off /mnt/...; for heavy/iterative work,
copy into ~ for speed:
cp -r /mnt/d/Projects/MyApp ~/MyApp && cd ~/MyApp && dotnet run| Task | Command |
|---|---|
| Check WSL status | wsl --status |
| List installed distros | wsl --list --verbose |
| List installable distros | wsl --list --online |
| Install Ubuntu LTS | wsl --install -d Ubuntu-24.04 |
| Launch Ubuntu |
wsl or click "Ubuntu" in Start menu |
| Check .NET version | dotnet --version |
| New console project | dotnet new console -o . |
| Build (Release) | dotnet build -c Release |
| Run | dotnet run -c Release |
| Windows C: in Linux | /mnt/c/... |
"has no installed distributions" — the engine is installed but no Linux distro
is. Run wsl --install -d Ubuntu-24.04.
Stuck on "Create a default Unix user account" — it's waiting for input. Type a username, press Enter, then type the (invisible) password and press Enter.
Command 'dotnet' not found — PATH not loaded. Run source ~/.bashrc, or open
a fresh terminal. Do not install dotnet via apt/snap as the suggestion text offers.
Want to run on a privileged port (< 1024, e.g. port 80) — that needs root.
Run with sudo, but note sudo resets PATH, so call dotnet by full path:
sudo $HOME/.dotnet/dotnet run -c Release.