Setting Up and Configuring WSL

Linux is by far the best operating system for developers, but, people still use Windows and other operating systems, or have another personal computer which for some reason uses Windows, and so you don't use Linux. Of course, you could literally install Linux onto your computer, but, if you can't, or, just want to have windows for accessibility, enter WSL - Windows Subsystem for Linux. WSL allows you to run a Linux Virtual Machine on your windows machine to run Linux commands and run .deb or .rpm files, depending on the distribution you choose.

Our steps

  • Install WSL
  • Install a Linux Distribution
  • Configure our Linux Distribution
    • Install VSCode, Python, and other development tools

Let's get started with install wsl.

1. Install WSL

First things first, we need to install WSL. Open your settings app on Windows, and click "Apps."

Once at the Apps menu, the right sidebar has a "Related Settings" section, which includes Programs and Features, which you need to go to. Once there, there should be a sidebar, where you should click "Turn Windows features on or off."

From this, you should have a screen like this:

Check the "Window Subsystem for Linux" box, and select Ok. After that, you should have a Restart now button, and click that.

2. Install a Linux Distribution

Now, we can install our Linux Distribution. You can install which ever distribution you want, but I'll be showing you the Ubuntu distribution. Go to aka.ms/wslstore, which will open up the Microsoft Store, showing you Linux Distributions. In the store, click "Ubuntu" and then "Install." Once installed, open up your command prompt, and run:

Ubuntu

If that doesn't work, you can open up the Ubuntu app, which should output something like this:
WSL installation output
From here, it will prompt you to enter your username and password, which can be anything, not your windows username and password, though, you could put that. Make sure you remember it, because we'll be using sudo to install, which requires you to enter your password. If you do lose it, you can run:

passwd <username>

which will reset your password.

3. Configure our Linux Distribution

Next thing we need to do is configure our distribution, and before we get into install VSC and Python, or anything else, we first need to configure our .bashrc with some useful aliases and other important scripts. Before any of this, create a new directory called Coding/ or Projects/, and clone all your repos there.

Next, we need to configure our .bashrc. First, run:

curl https://getmic.ro | bash
sudo mv micro /usr/bin

This will install micro and move it into the /usr/bin directory. For those of you who don't know, micro is a command line editor useful for editing small files from the terminal, like .bashrc, with keyboard shortcuts and other useful things. Now that we have it installed, you can run:

micro ~/.bashrc

to open .bashrc, and start editing it. You can add:

alias activate-<PROJECT>="cd <PROJECT_DIR>"

To quickly switch between projects. From here, you can also add other aliases or any other command you want to run on startup.

Now, we can start to install the tools we want to run. If you have Visual Studio Code, then normally you'd run:

code

to up VSC, but we need to do some extra configurations. Launch VSC- not from your linux distribution- and install the Visual Studio Code Remote - WSL extension. This will allow you to manage your Linux and Windows projects independently. Now, we can run:

code

to launch up VSC, and there might be some output which updates your Visual Studio Code, which is for your Linux distribution to install.

Anaconda

If you're like me and use anaconda, then you can use:

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh 
bash Miniconda3-latest-Linux-x86_64.sh

Now, whereis python should give you an output like /home/user/anaconda3/bin/python. If it doesn't, then anaconda isn't on path, so you can add to your .bashrc:

# ~/.bashrc

# Add to end of your bashrc.
export PATH=/home/user/anaconda3/bin:$PATH

This installs miniconda, but if you'd like all the built-in-packages, there are detailed instructions here.

Other great tools

I created this small gist which installs some basic stuff to get you going, including:

  • ZSH/
  • Git and others.

However, there's also starship which is an amazing shell, and I had a bit of trouble with the installation, so I'll bear you the trouble and show you how I installed it.

Starship

Fist, we need to install the binary:

sh -c "$(curl -fsSL https://starship.rs/install.sh)"

The next step varies on which shell your using. The previous gist installed ZSH, and if you'd like to use ZSH, then add the following line to .zshrc:

# ~/.zshrc

eval "$(starship init zsh)"

For bash users:

# ~/.bashrc

eval "$(starship init bash)"

And if you plan on using fish, you can add this to your fish config:

# ~/.config/fish/config.fish

starship init fish | source

There's a whole lot of other configurations out there, and you can view them here.
And you have starship!

But... if you want to make your starship stand out, like the one below, things get a little harder.
Nerd Font Starship Preset

We first need to configure starship. Run:

mkdir -p ~/.config && touch ~/.config/starship.toml

to create the config file, and open it up however you want:

code ~/.config/starship.toml # With VSC
micro ~/.config/starship.toml # With micro

Now, before we edit the config file, you need to download any Nerd Font, I chose FiraCode. You can download them from here- and move the zip file into \\wsl$\Ubuntu\home\{USERNAME}\. Extract the files, and then run:

mkdir ~/.fonts/
mv *.ttf ~/.fonts/
fc-cache -f -v

Now, extract the same file, just on your windows system, and then on file explorer, select all the TrueType Font Files, or .ttf files, and right-click them, and select the install button, which should install the font. Now, in Visual Studio Code, change the "Terminal.Integrated.Font Family" to "FiraCode Nerd Font", Monaco. Now, use the config from here and paste it into your starship config file. After that launch up your terminal in any project, and it'll show you something like this:

That's WSL! Comment any other cool things you added to starship, zsh, bash, or anything else related to the post that you think I might have missed!

32