5 Things to Do to Improve Your WSL Experience

Five Things Wsl Featured

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.

Also read: How to Install Linux on Windows with WSL

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
Zsh Install

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 curl and 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.

Five Things Wsl Default Shell
Five Things Wsl Oh My Zsh Installed

Also read: How to Reset a WSL User Password

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.

  1. 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.

Five Things Wsl Fonts
  1. Go to the fonts directory:
cd fonts
  1. Run .\install.sh in your PowerShell. This will install all the necessary fonts.
Five Things Wsl Fonts Install
  1. Open the WSL terminal again. Right-click on the top border and select Properties.
Five Things Wsl Properties 2
  1. 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.
Five Things Wsl Powerline Fonts Select

Customizing Zsh

Oh My Zsh comes with so many preinstalled themes, and we can use them by configuring our “~/.zshrc” file.

  1. In the WSL distro’s terminal, run:
nano ~/.zshrc
  1. Look for the line ZSH_THEME="robbyrussell" and replace it with ZSH_THEME="half-life".
  2. Press Ctrl + X to exit from the Nano text editor. This will ask if you want to save the file.
Five Thing Wsl Zsh Theme
  1. 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.
Five Things Wsl New Theme

You can find the names of all the preinstalled themes of Oh My Zsh here.

Also read: 8 of the Best Linux Distros for Windows Users

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.

  1. Create a new file in your Windows home directory called “.wslconfig.” In my case, the directory is “C:\Users\munna.”
  2. Paste these lines to the file and save it:
[wsl2]
memory=3GB
processors=2
Five Things Wsl Config

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.

  1. To let these changes take effect, shut down all the WSL instances. Do that by running wsl --shutdown from PowerShell.
Five Things Wsl Shutdown 1
  1. You can verify your new configuration for WSL using NeoFetch. Run neofetch from your WSL terminal.
Five Things Wsl Neofetch 1

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"
Five Things Wsl Git Config

Also read: How to Mount a Windows Share Folder on Linux

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.

  1. Install TightVNC by running:
sudo apt install tightvncserver -y
Five Things Wsl Install Tight Vnc
  1. 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.

Five Things Wsl After Installing Xfce
  1. 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.
Five Things Wsl Vncpassword
  1. We need to make sure that whenever we start the server, the desktop environment also starts:
echo "startxfce4 &">>~/.vnc/xstartup
Five Things Wsl Added Line

Installing a VNC Viewer

With a VNC server installed and running, we can use a VNC server to access it.

  1. Download VNC viewer from here.
  2. Enter your address in the VNC viewer’s address bar. It should be in ip:port format.
  3. If you don’t already have the address, run hostname -I in your WSL terminal. This will output your current IP address. Here, it is 172.20.89.160.
Five Things Wsl Hostname
  1. To find an accessible port for your TightVNC server, you can use the netstat command, which is a part of the net-tools package. To install net-tools, run:
sudo apt install net-tools -y
  1. We can use the netstat command. Run:
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.

Five Things Wsl Netstate
  1. 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 vncserver from the WSL terminal.
  2. Enter the VNC server’s address in the VNC viewer’s address bar. (Here, it is 172.20.89.160:5912.)
Five Things Wsl Vnc Viewers Addressbar
  1. It will ask you for your VNC server’s password. Enter the password and press “OK.”
Five Things Wsl Password Vnc

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.

Five Things Wsl Installed Vnc

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.

  1. To create a new script file, run:
nano ~/startvnc.sh

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.

Five Things Wsl Vnc Script

This will kill the first display session and remove the files associated with the session.

  1. Make the file executable by running:
chmod u+x ~/startvnc.sh
Five Things Wsl Chmod

From now on you can run “~/startvnc.sh” to start your VNC server at the first display session.

Five Things Wsl Start Vnc

Also read: 8 Reasons to Switch from Windows to Linux

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.

  1. Open File Explorer, and in the address bar type \\wsl$, then press Enter.
Five Things Wsl Dir

This will open your WSL distros’ directories.

Five Things Wsl Open Wsl
  1. Open your installed distro’s Home folder and find a folder with your WSL distro’s username.
Five Things Wsl Minix
  1. Pin the folder for quickly access by selecting the folder, right-clicking, and selecting “Pin to Quick access.”
Five Things Wsl Pin To
  1. You can transfer files between WSL and Windows from the File Explorer’s Quick access menu.
Five Things Wsl Useable

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.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Muhammad Munna

Muhammad Munna is an Electrical Engineering student who is passionate about technology and writing. He loves to experiment with different techs and dig deep into them. In his free time, he can be found fiddling with his smartphone camera.