Microsoft’s Windows Subsystem for Linux (WSL) is a game-changer that provides the best of both worlds (Windows and Linux). However, to get the best out of WSL, you can’t just rely on how it comes out of the box. This tutorial goes over five things that can make your WSL experience even better.
We are using WSL 2 and Ubuntu throughout this article, but you can apply these tips to any distro.
1. Installing Zsh
Zsh, also known as Z-shell, is a more powerful and customizable shell than Bash shell, the default shell for most Linux distros. Zsh comes with advanced features like autocompletion, autocorrection, built-in Git integration, and support for installing themes and plugins.
To install Zsh, run:
sudo apt install zsh -y
With Zsh installed, you can install frameworks like Oh My Zsh to manage Zsh.
Installing Oh My Zsh
Oh My Zsh is an open-source, community-driven framework that lets you manage themes and plugins for Zsh in a more convenient way.
You can install Oh My Zsh using
git, which come preinstalled with most of the WSL distros. If you don’t have them installed, you can always install them using
sudo apt install curl git.
Now that we have cURL and Git installed, run:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
This will clone the repository and install Oh My Zsh. In the installation process you will be prompted with the question “Do you want to change your default shell to zsh?” Press Y and Enter to make it your default shell.
Installing Powerline Fonts for Zsh
You might have noticed some weird symbols showing on the terminal. This is because we don’t have the appropriate fonts (Powerline) installed.
- Open PowerShell on Windows, and from your Windows home directory, run:
git clone https://github.com/powerline/fonts.git
This will clone the fonts in your Windows home directory of Windows.
- Go to the fonts directory:
.\install.shin your PowerShell. This will install all the necessary fonts.
- Open the WSL terminal again. Right-click on the top border and select Properties.
- You can customize your WSL terminal from here. Here, we’re selecting the “Font” tab and using “DejaVu Sans Mono for Powerline” fonts, but you can use any Powerline font you want. Press “OK” after selecting your font.
Oh My Zsh comes with so many preinstalled themes, and we can use them by configuring our “~/.zshrc” file.
- In the WSL distro’s terminal, run:
- Look for the line
ZSH_THEME="robbyrussell"and replace it with
- Press Ctrl + X to exit from the Nano text editor. This will ask if you want to save the file.
- Press Y and Enter to save the file. Restart your WSL terminal by closing and reopening it. You will see that the new theme has taken place.
You can find the names of all the preinstalled themes of Oh My Zsh here.
2. Configuring WSL to Limit Its CPU and Memory Usage
WSL can be quite resource hungry and a memory hog, especially when you are using applications like Docker, which can take up a lot of your usable memory. The problem is, sometimes it doesn’t unallocate your memory, even if it doesn’t need that extra memory anymore. This can result in your entire PC slowing down and even lagging. You can easily fix this issue by limiting how much memory and how many CPU cores WSL can access.
- Create a new file in your Windows home directory called “.wslconfig.” In my case, the directory is “C:\Users\munna.”
- Paste these lines to the file and save it:
[wsl2] memory=3GB processors=2
This will set the maximum memory usage limit to 3GB, and WSL will have access to two virtual processors. For example, if your CPU has four threads, WSL can now access two of those.
- To let these changes take effect, shut down all the WSL instances. Do that by running
wsl --shutdownfrom PowerShell.
- You can verify your new configuration for WSL using NeoFetch. Run
neofetchfrom your WSL terminal.
You can also configure your WSL for things like limiting the swap usage, turning on console debugging, and using a custom kernel. You can check out Microsoft’s official docs for all the configurable options.
3. Using Windows Git Credential Manager on WSL
If you have used Git in WSL, you might have already noticed that WSL keeps asking for your Git credentials every time you push something on GitHub.
To fix this, you can use your Windows Git credential manager for WSL and have the same credentials across Windows and WSL.
To set your WSL’s Git to use Windows Git credential manager, run the following command in your WSL terminal:
git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/libexec/git-core/git-credential-manager.exe"
4. Using a VNC Server to Use GUI Apps on WSL
Although WSLg can run GUI apps, it’s only limited to Windows 11 and Windows 10 insider versions. Also, running a desktop environment is a mess in WSLg. A VNC server can come in handy if you want to access your Linux distros remotely.
- Install TightVNC by running:
sudo apt install tightvncserver -y
- Now we need a desktop environment for our Linux distro. Let’s install Xfce, which is a lightweight Linux distribution:
sudo apt install xfce4 xfce4-goodies
This will prompt you with two options for your display manager. We’re using lightdm here, but you can choose either one. Select “Ok” after choosing your preferred display manager.
- Run TightVNC using the command
vncserver. You will be asked for a password for your VNC server. Enter a password that is at least eight digits. When prompted to verify, just re-enter your password. You will be asked if you would like to enter a view-only password. Press N, as view-only passwords will only let you view the Linux distribution and not interact with it.
- We need to make sure that whenever we start the server, the desktop environment also starts:
echo "startxfce4 &">>~/.vnc/xstartup
Installing a VNC Viewer
With a VNC server installed and running, we can use a VNC server to access it.
- Download VNC viewer from here.
- Enter your address in the VNC viewer’s address bar. It should be in
- If you don’t already have the address, run
hostname -Iin your WSL terminal. This will output your current IP address. Here, it is
- To find an accessible port for your TightVNC server, you can use the
netstatcommand, which is a part of the net-tools package. To install net-tools, run:
sudo apt install net-tools -y
- We can use the
sudo netstat -natl
From the output, copy the port number under the “Local Address” column. Here, it is showing
0.0.0.0.0:5912 under the first “Local Address” column. The port number starts after
: and is 5912. If you face issues like VNC Viewer taking too long to connect, you can retry with a different port from the “Local Address” column.
- If netstat doesn’t show any port number, that means your TightVNC server is not running. You can always start your VNC server by running
vncserverfrom the WSL terminal.
- Enter the VNC server’s address in the VNC viewer’s address bar. (Here, it is
- It will ask you for your VNC server’s password. Enter the password and press “OK.”
You can use the WSL’s Linux distro in a GUI environment and install any GUI app in your Linux distro and use it through the VNC viewer.
Using a Script to Start the VNC Server
The VNC server creates a new display session every time you run
vncserver. We can create a script to avoid that.
- To create a new script file, run:
and add these lines:
!/bin/bash vncserver -kill :1 > /dev/null 2>&1 rm -f /tmp/.X1-lock rm -f /tmp/.X11-unix/X1 vncserver -geometry 1920x1080
and save the file.
This will kill the first display session and remove the files associated with the session.
- Make the file executable by running:
chmod u+x ~/startvnc.sh
From now on you can run “~/startvnc.sh” to start your VNC server at the first display session.
5. Transferring Files from Windows to WSL Easily Using File Explorer
Although you can transfer files from Windows to WSL, having a GUI environment for copying and moving your files comes in handy. You can use the built-in File Explorer of Windows for transferring your files using a graphical interface.
- Open File Explorer, and in the address bar type
\\wsl$, then press Enter.
This will open your WSL distros’ directories.
- Open your installed distro’s Home folder and find a folder with your WSL distro’s username.
- Pin the folder for quickly access by selecting the folder, right-clicking, and selecting “Pin to Quick access.”
- You can transfer files between WSL and Windows from the File Explorer’s Quick access menu.
Frequently Asked Questions
Can I use an IDE on WSL using a VNC server?
Yes, you can use IDE in your Linux distribution using WSL. Although the performance is not the same as native apps, it’s quite usable.
Am I limited to the preinstalled themes of Oh My Zsh?
No. Besides the preinstalled themes, you can also install third-party themes for Zsh.
Do I have to configure WSL for each of my Linux distros?
No. Any configuration changes to WSL will be applied to all of your installed Linux distros.
Our latest tutorials delivered straight to your inbox