Ubuntu Setup with WSL2

Jordan Gardner
4 min readJun 24, 2021

I recently upgraded from being a Mac-only user and built myself a PC! I told my wife it was a backup in case my Macbook Pro ever had issues, so I decided I better make sure I can actually do work with it. Getting everything configured wasn’t too difficult, but there’s more than a few steps and I decided to document them here.

Please note that this setup is very opinionated and configures specific tools that I use in my daily work — YMMV.

Windows Subsystem for Linux (WSL)

From the docs:

The Windows Subsystem for Linux lets developers run a GNU/Linux environment — including most command-line tools, utilities, and applications — directly on Windows, unmodified, without the overhead of a traditional virtual machine or dualboot setup.

Since it’s original release, Microsoft has made some improvements and now offers WSL2. You can learn more about the differences here.

Microsoft docs do a pretty good job helping get WSL2 installed and configured so go ahead and follow their instructions to get started:

Windows Terminal

Install Windows Terminal. This is an optional step in the Microsoft docs for getting WSL2 configured, but you’d be a fool not to.

Ubuntu

Next, install Ubuntu.

After installing Ubuntu, open it directly from the start menu. The initial launch completes the installation process and has you set up your main user account in Ubuntu.

Follow the prompts to setup your user account and password.

Configure Windows Terminal

Now that we have the main software installed, we can start configuring our setup.

First, we need to open up Windows Terminal and set the default profile to Ubuntu, cuz I don’t care what anybody says PowerShell is garbage.

NOTE: You must install Ubuntu first and open it to complete installation before opening Windows Terminal or else it won’t appear in the list of available profiles.

Use the dropdown arrow in the top of the window to access the settings page. On the very first page change the Default Profile to Ubuntu, then click Save.

If you open up a new tab, you should see your Ubuntu install ready to go!

You’ll also notice the default starting directory is your Windows home directory. That’s not helpful, so let’s change it.

Open up the settings again and on the left-hand side under Profiles, select Ubuntu. In the General section, change the Starting directory (remember to use your username) to the following

\\wsl$\Ubuntu\home\[your-username]

Here’s what my settings look like after the change:

Make sure to click Save and voilà! We now have an appropriate setup to start working in our shell.

sudo

You’re going to be running sudo quite a bit when using Ubuntu, so let’s go ahead and make sure you don’t have to type in your password every time you do.

sudo visudo -f /etc/sudoers.d/vips

This should be one of the few times you have to enter your password. Once the file is open for editing, add the following

[your-username] ALL=(ALL) NOPASSWD:ALL

Here’s what mine looks like

jordan ALL=(ALL) NOPASSWD:ALL

Go ahead and Ctrl-X to exit visudo and follow the prompts to save the file. You should now be able to sudo to your hearts content!

Now would be a good time to update Ubuntu and make sure everything is fresh

sudo apt update && sudo apt upgrade -y

Zsh and Oh My Zsh

I’ve grown very fond of using Zsh (Z shell) and Oh My Zsh so let’s get that configured as well.

First, install zsh and set is as your default shell

sudo apt install zsh
chsh -s $(which zsh)

Then restart your shell. zsh will prompt you to configure your shell the first time you reopen your terminal, but you can just q out of it since Oh My Zsh will override whatever you set.

Let’s get Oh My Zsh installed now

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Fin

You’re all geared up and ready to go! I highly recommend getting VSCode and the Remote-WSL plugin for editing files

Docker works great between systems as well should you need it

Happy day.

--

--