Setting Up and Configuring WSL
Tags: windows, linux, wsl, bash
Published: 2021-07-28 20:51:25

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

![Apps Menu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8a6g4tdd6fw4q4b18r4o.png)

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

![The Windows Sidebar](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gy6x15j4cqf12lvd5zbb.png)

From this, you should have a screen like this:
 
![Turn Windows features on or off Menu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dnx99nrff3ulu15tgz57.png)

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](https://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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h5zfd1u1r14i9tvrsc3c.png)
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:
```bash
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:
```sh
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:
```sh
micro ~/.bashrc
```
to open `.bashrc`, and start editing it. You can add:

```sh
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:
```bash
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:
```sh
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:
```bash
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`:
```bash
# ~/.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](https://gist.github.com/kauffmanes/5e74916617f9993bc3479f401dfec7da).

### Other great tools

I created [this small gist](https://gist.github.com/Quantalabs/8640dfca495248daf997951a77d69b4c) which installs some basic stuff to get you going, including:
- ZSH/
- Git
and others. 

{% gist https://gist.github.com/Quantalabs/8640dfca495248daf997951a77d69b4c %}

However, there's also [starship](https://starship.rs) 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
![Starship](https://avatars.githubusercontent.com/u/49654870?s=200&v=4)

Fist, we need to install the binary:
```bash
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`:
```bash
# ~/.zshrc

eval "$(starship init zsh)"
```
For bash users:
```bash
# ~/.bashrc

eval "$(starship init bash)"
```
And if you plan on using fish, you can add this to your fish config:
```bash
# ~/.config/fish/config.fish

starship init fish | source
```
There's a whole lot of other configurations out there, and you can view them [here](https://starship.rs/guide/#%F0%9F%9A%80-installation).
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](https://starship.rs/presets/nerd-font-symbols.png) 

We first need to configure starship. Run:
```bash
mkdir -p ~/.config && touch ~/.config/starship.toml
```
to create the config file, and open it up however you want:
```bash
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](https://nerdfonts.com/font-downloads)- and move the zip file into `\\wsl$\Ubuntu\home\{USERNAME}\`. Extract the files, and then run:
```bash
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](https://starship.rs/presets/#configuration) 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:

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u9hqwucgvo4th3de75dj.png)

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!