ScottSpence.com

Scott's Thoughts Pamphlet!

WSL Web Developer Bootstrap with Fedora 33

I have been having a blast playing around with configuring Fedora 33 in Windows via Windows Subsystem for Linux, I didn’t know you could straight up import a Linux distro and use it.

In this guide I’ll go through the complete setup needed to go from initial install of Fedora 33 right through to running GUI tools like Cypress and Puppeteer!

There’s a great resource I found in Fedora Magazine and another post in Dev.to, the Dev.to one I haven’t tried as the first guide does all I need it to do so it’s there for reference if needed.

This is my bootstrap for getting set up with Fedora 33 and all the related bits of software I’ll need for wed development with it.

Prerequisites

If you haven’t already got Windows Subsystem for Linux Installed then take a look at the official guidance from Microsoft.

I’d also suggest checking out Nicky Muleman’s post on it.

Get Fedora 33 for use in WSL

First up! Importing the Fedora 33 distribution.

Credit to Jim Perrin for the original post in Fedora Magazine on this.

Get the Dockerhub container image which is what I’ll be using for the Linux instance, this is because Fedore doesn’t ship with rootfs so I’m jacking this one from GitHub.

I’ll download the image and put it on my C drive in a distros folder.

The file is downloaded as a *.tar.xz file, I need to extract this so it’s a *.tar file, I use 7zip to do that.

Import into WSL

Time to import the *.tar into WSL, I’ve already created a distros folder on my C drive, now to point PowerShell to the file and import:

1wsl --import Fedora-33 C:\Users\scott\distros\ C:\Users\scott\distros\fedora-33.20201230-x86_64.tar

To break down that command, wsl is clear what that is hopefully, with the --import denoting that what is being imported is called Fedora-33 and it should live in the C:\Users\scott\distros\ folder, and the place to import from is C:\Users\scott\distros\fedora-33.20201230-x86_64.tar.

Now to check out the installed versions available on my machine with wsl -l -v, I’ve removed all the other Linux installs I have for brevity but leaving Ubuntu there with the * next to it denoting it as the default:

1# the l is for list
2# v is for verbose 🤷‍♀️
3# this is the long version => wsl --list --verbose
4PS C:\Windows\system32> wsl -l -v
5 NAME STATE VERSION
6* Ubuntu Stopped 2
7 Fedora-33 Running 2

Update and install core packages

Now it’s imported I can access it in PowerShell with:

1wsl -d Fedora-33

This is the root user so I’ll need to my user account in a minute first up though it’s the update dance we alway do in Linux, with Fedora it’s dnf you use in place of apt like what’s used in Ubuntu.

1# update all the things
2dnf -y update
3# install core packages
4dnf install -y wget curl sudo ncurses dnf-plugins-core dnf-utils passwd findutils

These are what’re recommended on Jim’s post so I’m going with this for now, I’ll add additional packages once I have created my user details.

Add my user

So, my user is scott if you’re following along you’ll need to change that.

1# create user and add them to sudoers list
2useradd -G wheel scott
3# set password for user
4passwd scott

Time to exit this shell and go back in as my newly created user to check the credentials.

1# exit current shell with
2exit
3# back in PowerShell now
4wsl -d Fedora-33 -u scott
5# get user id
6id -u
7# id -u returns 1000
8# test that user is on sudoers list
9sudo ll

That last command will prompt me for the password I created for scott, presuming that went well then it’s time to set the default user.

To do that, exit WSL to get back into Powershell.

This PowerShell one-liner configures my user properly, (thanks Jim!) take note of the last value here 1000 that’s the id -u I checked for earlier:

1Get-ItemProperty Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\*\ DistributionName | Where-Object -Property DistributionName -eq Fedora-33 | Set-ItemProperty -Name DefaultUid -Value 1000

The last piece here is to add Copr for the Windows integration:

1# in the Fedora shell
2sudo dnf -y copr enable trustywolf/wslu

Install additional packages

Ok, now to get moving with the bits I need for web dev, fist I’ll want to add nano and git:

1sudo dnf -y install nano git

Then for using end to end testing and automation tools like Cypress, Playwright and Puppeteer I’ll first want to install some browsers which will add all the needed libs and packages I’ll need later:

1sudo dnf -y install firefox chromium

Install Zsh and Oh My Zsh

Zsh has become quite special to me so this is a must for me, if you’re following along then you do you, the majority of the config here can be done with bash too.

1sudo dnf -y install zsh

Then OMZ with:

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

Oh My Zsh will say:

I can’t change your shell automatically because this system does not have chsh. Please manually change your default shell to zsh

I’ll do that next.

Change default shell

There’s no chsh utility in Fedora so if I want to change the default shell then I’ll need to do this:

1# open the passwd file
2sudo nano /etc/passwd

Look for something like:

1scott:x:1000:1000::/home/scott:/bin/bash

Look for the part with my username, then change the /bash part with /zsh

Save the changes in nano with Ctrl+o to write out the changes then Ctrl+x to exit out of nano.

Customise Zsh

I’ve gone over this a couple of times now, if you’re not interested skip along to the next bit.

I’m going to add a few things here, these are essentials for me:

Plugins:

Theme, very important:

Install the plugins first:

1# zsh-syntax-highlighting
2git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
3# zsh-autosuggestions
4git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

Update the plugins array with some added ones from Oh My Zsh:

1plugins=(
2 git
3 node
4 npm
5 npx
6 nvm
7 zsh-syntax-highlighting
8 zsh-autosuggestions
9)

And remember to add the auto suggest config to the .zshrc config file:

1ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#663399,standout"

Now for the theme, first up clone and symlink the repo:

1# clone the repo first
2git clone https://github.com/denysdovhan/spaceship-prompt.git "$ZSH_CUSTOM/themes/spaceship-prompt" --depth=1
3# symlink it
4ln -s "$ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" "$ZSH_CUSTOM/themes/spaceship.zsh-theme"

Then set it to the .zshrc file:

1# nano ~/.zshrc
2ZSH_THEME="spaceship"

Add starting directory

Add the starting directory to be in the Linux partition.

1# cd to the home directory
2~
3# mkdir for repos
4mkdir repos
5# Open the zshrc file
6nano ~/.zshrc
7# add this at the bottom
8cd ~/repos

Add SSH keys

I have one set of SSH keys I keep for my WSL instances, I’ll copy those to my user home folder with the explorer.exe tool, pop open the explorer:

1explorer.exe .

Paste in my .ssh folder and .gitconfig, one thing to note here is that sometimes copying files in will set the permissions on the files to root, check that with:

1# check the .ssh file permissions
2ls -lart .ss*
3# if it shows root as the owner then change it
4-rw-r--r-- 1 root root 749 Aug 25 17:36 id_rsa.pub
5-rw-r--r-- 1 root root 3389 Aug 25 17:36 id_rsa

A really handy way to find the ordinals on a file, (so the numbers instead of -rw-r--r-- whatever that means) is stat, this command will give the actual numbers:

1stat -c "%a %n" ~/.ssh/*

That gives an output like this:

1644 /home/scott/.ssh/id_rsa
2644 /home/scott/.ssh/id_rsa.pub
3644 /home/scott/.ssh/known_hosts

So after I change owner I know I’ll need to change the id_rsa to 600 from 644.

In this example the owner is root so I’ll change it to my user (scott):

1# change ownership of folder and contents
2sudo chown scott:users .ssh/ .ssh/* .gitconfig

Now to change the permissions on the id_rsa file and authenticate with GitHub:

1# change to the .ssh/ folder
2.ssh/
3# set permission
4sudo chmod 600 id_rsa
5# change out to set the folder permissions
6../
7sudo chmod 700 .ssh/
8# authenticate with GitHub
9ssh -T git@github.com

Install nvm

Install nvm for that Node version goodness:

1curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | zsh
2source ~/.zshrc
3command -v nvm
4# sets default to 14
5nvm install 14
6# nvm alias default 14

Install Yarn

Install Yarn with the instruction for the Yarn docs:

1curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
2sudo dnf -y install yarn

Install a global yarn package and make sure global binaries are showing.

In this case I’ll add Vercels CLI:

1yarn global add vercel

Then try to login with vc login I get a response of:

1zsh: command not found: vercel

So I need to set the prefix:

1# confirm global path
2yarn global bin
3yarn config get prefix
4# When I ran this it was undefined, so I set it:
5yarn config set prefix ~/.yarn

Add the following to my ~/.zshrc file:

1export PATH="$PATH:`yarn global bin`"

Reload the shell:

1source ~/.zshrc

And try again:

1vercel login

Set the $DISPLAY variable

Unlike with the Fedora Remix for WSL the display variable needs to be set in Fedora 33, so I’ll go through the same process as I did in my Enable GUIs WSL post. Credit to Nicky Muleman and his post that give me the initial details.

1# set DISPLAY variable to the IP automatically assigned to WSL2
2export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0

Run a project that uses a GUIs

I have an xserver in x410 that’s already running, if you need to set up an xserver check out Nicky’s post on getting it set up.

I’m going to clone MDX Embed as I know it uses Cypress and run the command to do end to end tests with Cypress once it’s finished installing:

1git clone git@github.com:PaulieScanlon/mdx-embed.git
2# then install dependencies
3yarn
4# and run yarn cy:test to test
5yarn cy:test

References and tips

Now that I’ve installed all the things I need I can run:

1sudo dnf clean all

This will clear up all the unused files.

If I want to start over I can use:

1wsl --unregister Fedora-33

This will remove the Fedora install so I can start again.

Wrap!

that’s it, I’ve gone and installed an off the shelf version of Linux on my Windows machine and configured it for use in web development.

Back to Top


Scott Spence

Built with Gatsby · Hosted on Vercel · 2021