If you’re using WSL, how can you make it even better?
Get Windows Terminal
While you’ll get a terminal window when you install a Linux distribution from the Microsoft Store, there are better options for your terminal.
One of them is Microsoft’s own Windows Terminal. This application includes a lot of the features that you expect from other modern terminal emulators, including tabbed windows. Windows Terminal not only handles Linux but also PowerShell and the good old Command Prompt.
It’s still a little rough around the edges. You have to edit your settings in a .json file. If you’re a heavy command line user, you will probably be comfortable editing configuration files anyway.
Download: Windows Terminal
Change Your Shell
On most Linux distributions, including Ubuntu, the default shell is Bash. There’s nothing wrong with it, but experienced Linux users are often unsatisfied with the way the system comes out of the box. Everyone likes to tweak it, and the shell is no exception.
One popular bash alternative in the Unix/Linux world is zsh. It’s already the default shell in Apple’s macOS. You can easily switch to a different shell in one command.
On most Linux distributions, zsh is not installed by default. In Ubuntu, you can install it using apt:
To change your shell to zsh in Ubuntu WSL, type:
The location of the shell that you want to use might be different if you’re using another distro. You’ll be prompted for your password to change the shell. To find the location of your shell, type:
If you want to use a different shell, you should replace zsh with the name of that shell.
Access Windows and Linux Files
Not only does WSL enables you to run Windows and Linux programs side by side, it also helps in accessing files on the Windows and Linux systems simultaneously.
This is really handy for development projects. You can edit a program in a Windows editor and test it in a Linux window.
The Windows file system is mounted on the Linux side in the /mnt/[drive letter] directory. If your Windows drive is C, it will be /mnt/c. You can access all your Windows files using standard Linux commands this way.
Accessing the Linux filesystem from Windows is also easy. It’s visible under the \wsl$ hierarchy in Windows Explorer. Windows sees the Linux system as a network drive. If you have Ubuntu 20.04 installed, it will be \wsl$\Ubuntu-20.04.
To open up an Explorer window of the current directory type:
Upgrade to WSL 2
In 2020, Microsoft introduced WSL 2. The main improvement over WSl 1 is its use of an actual Linux kernel, delivered via Windows update. This improves performance, as the kernel executes Linux system calls instead of having to translate them into Windows system calls.
To upgrade to WSL 2, all you have to do is issue a few commands. First, you activate the hypervisor. Open a PowerShell window as an administrator and type:
Then restart your machine.
Next, you’ll need to download the Linux kernel. Get the package from Microsoft’s website and run the installer.
Download: Linux Kernel for WSL
Now you’ll want to set version 2 as the default for any distributions you’ll install in the future:
But you’ll want to upgrade any existing installations to WSL 2. Fortunately, that’s also pretty easy.
To see which distributions you have installed, type:
If you want to set your Ubuntu 20.04 installation to WSL 2, use the –set-version option:
Now you’ll be running WSL 2 with all of its advanced features on your current and future installations, and the kernel will be upgraded with Windows Update, just as with any other drivers on your system.
Gather Your Tools
Linux remains popular among developers due to the staggering amount of programming tools, such as editors, compilers, IDEs, server software, etc. that’s available on the platform.
It’s easy to equip your new WSL-based installation with your favorite tools as it is on other systems. All you have to do is use the standard package manager that comes with your system.
On Debian and Ubuntu, it’s apt. On SuSE, It’s YaST. On Alpine, it’s APK. The point is, you’ll find everything you need to run your favorite development projects on WSL as you would on a conventional Linux installation.
If you’re a C programmer, Debian and Ubuntu include a package called build-essential that consists of the GCC compiler, the C library, the Make utility, and package development tools. It’s really intended for people working on the distribution itself, but also handy for general C development.
To install it, you just use an apt command:
It pays to browse the package listings to make sure your favorite tool is there and perhaps find some new ones.
Managing Services
While most of the time in WSL you’ll be running regular commands, sometimes you might need to start and stop services. You might be developing a web application and need to test it using a web server.
Fortunately, it’s easy to start and stop services, just as you would on any other Linux distribution.
It’s a little different in Ubuntu under WSL, because it doesn’t use Systemd to manage its services, but uses the Service utility, which uses the older System V-style init scripts to manage services.
If you want to start the Apache server, you’d just issue this command:
This will launch the Apache server. You can check the running services using the top command and see apache2 in the list of processes.
Stopping the Apache server is just as easy:
Explore Different Distros
A lot of the fun of WSL comes from the way you can run different distros at the same time, so why not take advantage of running something less-known like Alpine Linux alongside Ubuntu or SuSE or Debian? Perhaps you might find your new favorite. If you like a distribution, you can set it as your main distro using the –set-default flag:
where distro-name is the name of the system you want to change to.
Exploring WSL
WSL has a lot of options for exploring the new world combining Linux and Windows. It seems that there’s always something new to discover. You can change the shell, change the terminal, start and stop services, and check out different distros.
The Windows Subsystem for Linux has lots of features that are quite different from a Linux distribution. But you can still benefit from using WSL as it allows you to quickly access a Linux system from your Windows machine.