How to install Arch Linux for WSL
Tags: archlinux, wsl, powershell, windows
Published: 2022-10-06 21:06:10

---
title: How to install Arch Linux for WSL
published: true
description: Building a better environment for windows development
tags: ArchLinux, WSL, Powershell, Windows
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rl9bsq16b748043hf6b5.png

---

> **UPDATE! 10/11/2022** This post has been deprecated. See [this post](https://dev.to/jrcharney/archwsl-brings-arch-linux-to-wsl-and-more-1jm4) which supersedes it. 

I am currently going through another coding camp right now.

Although this environment is not part of the course, it is of benefit to anyone looking for a smarter, more dynamic environment for developing on Windows using Linux.

## How I set up Arch Linux for WSL

**Windows Subsystem for Linux** (WSL) is a way to use Linux on Windows without re-partitioning your hard drive or using a Virtual Machine like [Virtual Box](https://www.virtualbox.org/).

You need to install something called [Hyper-V](https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v) if you want to use Windows Subsystem for Linux (WSL). It can NOT be installed with Window 10 Home, but should work with Windows 11 Home. This will require a reboot.

Right click on the Windows menu and select "Powershell (Administrative)".  If you are using Windows 11, open "Windows Terminal (Administrative)".  We will enable Hyper-V in the command line rather than going through a bunch of other Windows like I had to do.

```powershell
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
```

You probably should enable Hyper-V with the Deployment Image Servicing and Management tool (DISM) to help configure windows and Windows images.  This will allow DISM to enable Windows features while the operating system is running.

```powershell
DISM /Online /Enable-Feature /All /FeatureName:Microsoft-Hyper-V
```

When the installation is completed, reboot and come back here.

From the Microsoft Store App, you should install the [Windows Terminal](https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701?hl=en-us&gl=us) application and also [Visual Studio Code](https://apps.microsoft.com/store/detail/visual-studio-code/XP9KHM4BK9FZ7Q?hl=en-us&gl=us). If you have Windows 11, you should already have Windows Terminal.


## Get a Windows Installer

You should install either [Chocolatey](https://chocolatey.org/) or [Scoop](https://scoop.sh/) so you can download some stuff in the command line, especially the [NerdFonts](https://www.nerdfonts.com/) that are required for Powerline, Powerlevel10k, and VS Code.  These fonts have extra characters that can be used in the Windows Terminal.

I recommend Scoop (`scoop`) over Chocolatey (`choco`) because it is better organized. Packages are grouped into "Buckets".

### Installing Scoop

```powershell
Set-ExecutionPolicy ByPass -Scope Process -Force
$env:SCOOP='C:\Applications\Scoop'
$env:SCOOP_GLOBAL='C:\GlobalScoopApps'
[Environment]::SetEnvironmentVariable('SCOOP_GLOBAL', $env:SCOOP_GLOBAL, 'Machine')
iex "& {$(irm get.scoop.sh)} -RunAsAdmin"
```

> Note: we can't use `irm get.scoop.sh | iex`, not even in an Administrative PowerShell! (This is why PowerShell sucks!)
>
> If `iex "& {$(irm get.scoop.sh)} -RunAsAdmin"`  doesn't work, try running `irm get.scoop.sh -outfile 'install.ps1' ; .\install.ps1 -RunAsAdmin`. This will create `install.ps1` locally, which you will need to `del install.ps1` later.

We need to set the execution policy to `Bypass`. We could have also used `Set-ExecutionPolicy RemoteSigned -Scope CurrentUser` which would have set the execution policy to `RemoteSigned`. You can see what execution policy is used by running `Get-ExecutionPolicy`.

We should get `scoop` to work. Let's update it.

```powershell
scoop update
```

## Get the NerdFonts

Because the entire set of NerdFonts is about a couple of gigabytes, you should just get the essential fonts.

I recommend installing these fonts from NerdFonts.
- Meslo
- FiraCode
- FiraMono
- Hack

We first need to add the `nerd-fonts` bucket.

```powershell
scoop bucket add nerd-fonts
```

Next install the font packages

```powershell
scoop install Meslo-NF Meslo-NF-Mono Hack-NF Hack-NF-Mono FiraCode-NF FiraCode-NF-Mono FiraMono-NF FiraMono-NF-Mono
```

You should be able to set your Windows terminal to use one of the fonts we installed by going to the settings.  A lot of folks are recommending using Meslo.

## Installing ArchWSL

We need to get ArchWSL from the `extras` bucket.  Before we run WSL for the first time, we need to set it's version to version 2. This will use WSL2, which is recommended. We can view what version our Linux distribution is using later with `wsl -l -v`.

```powershell
wsl --set-version 2
scoop bucket add extras
scoop install archwsl
```

You might have seen a message at the end saying "Even when you are logging in as 'root', some operations (like service command) require Windows administrator privileges". This is nothing to worry about. We're going to do something in a little bit so we don't have to log in as root directly.

> Note: To view what Linux distributions are available, we can use `wsl -l`. To view version information, we can use `wsl -v`. Combining `-l` with `-v`, we can see what version of WSL we are using and what Linux distribution is being used with `wsl -l -v`.

We are now ready to take care of some basic tasks to get Arch Linux up and running.

Start by running the `Arch.exe` program.

```powershell
Arch.exe
```

First lets set our root password with `passwd`, you could use your windows password, but a different password would be more secure.

> NOTE: Bash is set up to show the current username of the user that is logged in, and the machine that you are logged into. This is called the **prompt**. Later we'll do some stuff to make it look pretty. I would recommend giving your computer a name instead of `"Dell-XPS_13-bunch_of_numbers"`.  You can do that in your Windows setting. For now well, call our PC "Crystal". This will show up if we run the command `uname -n`.
> Our prompt in Bash will also use `#` if root (the administrator) is logged in and `$` if a regular user is logged in.

```bash
[root@crystal]# passwd
```

Once you have set up your root password, let's create our regular user and give them permission to use the `sudo` command that temporarily gives them the power to run root command with the `sudo` prefix.

```bash
[root@crystal]# echo "%wheel ALL=(ALL) ALL" > /etc/sudoers.d/wheel		# This creates the sudoers file
[root@crystal]# useradd -m -G wheel -s /bin/bash jrcharney			# Create a new users. I will set mine for jrcharney
[root@crystal]# passwd jrcharney						# Set the password for the new user
[root@crystal]# exit								# Return to powershell
```

We need to return to the Powershell for a moment to set the default user.

```powershell
Arch.exe config --default-user jrcharney					# Note: Use your username not mine!
```

> Note: If the above command doesn't work, try restarting the `LxssManager` in an Administrative Powershell/Windows Terminal.
> Do this by running these two command: `net stop lxssmanager`  then `net start lxssmanager`
> Contrary to what the [ArchWSL Setup documentation](https://wsldl-pg.github.io/ArchW-docs/How-to-Setup/) says, you can't use `&&` in Powershell. But that's not going to matter once we get this running.
> If that doesn't work, try restarting the computer, but that should only be a last resort.

Once we have our default user, we can launch `Arch` again.  Thanks to how ArchWSL is set up, `Arch` will be a option in our dropdown menu on the Windows Terminal, but we can't set it as the default option. That will still need to be PowerShell because Microsoft.

But that's no big deal, because the next time we start our Linux terminal, you should see something like this as your user prompt.

```bash
[jrcharney@crystal]$
```

Congratulations! You now have LINUX installed on Window! This next part will add all those rad toys to it to make it look awesome and a lot less scary.

## Set up Arch Linux

If this were actually Arch Linux, we could have used a script called `arch_install` to knock out some of this stuff. Since we don't have it, we got to do it manually.

Here's just the quick summary of everything I ran to get mine set up.  The first few packages we install will be the ArchLinux keyring, the base development tools, Git, another package manager called `yay` that will let us use the ArchLinux User Repo (AUR), and short list of other cool stuff.

> Note: I'm not going to write the prompt anymore. Almost everything will be done as your default user, even the `sudo` commands.

```bash
sudo pacman-key --init
sudo pacman-key --populate
sudo pacman -Syu
sudo pacman -S archlinux-keyring 											# Note: ArchWSL says this is optional, but THIS PACKAGE IS MANDITORY! It should be the first one installed.
sudo pacman -S --needed base-devel git										# When you install the `base-devel` package for ArchWSL, `fakeroot` and `fakeroot-tcp` are in conflict. When asked if you want to replace `fakeroot-tcp` with `fakeroot` SAY NO!
sudo git clone https://aur.archlinux.org/yay.git							# This will install `yay` which will allow you access to the ArchLinux User Repository.
cd yay																		# Go to the yay directory  (TODO: Could I have put this in a Downloads directory?)
makepkg -si																	# Make the `yay` package, this will also install the Go Language (`golang`) that `yay` needs to do stuff.
sudo pacman -S openssh														# Install OpenSSH so we can use SSH.
sudo pacman -S github-cli													# Install this so we can use `gh` to do github command. (TODO: Is there something similar for gitlab?)
sudo pacman -S lolcat														# Install `lolcat` (colorful cat), this will also install the Ruby programming language that it depends on.
sudo pacman -S bat															# `bat` is like `cat`, but it looks better.
sudo pacman -S bat-extras fzf clang llvm rust								# Some important tools I'll talk about them later.
sudo pacman -S python-pip													# Python needs pip to install some packages
sudo pacman -S lm_sensors psutils python-psutil neofetch bashtop htop		# Install these to show system information and to manage processes in a more user-friendly way
sudo pacman -S figlet cowsay fortune-mod cmatrix nyancat					# Command line toys, some of them are important that they install some depedencies you'll want to have around.
sudo pacman -S ponysay														# It's like cowsay, only 20% cooler.
yay -S bash-pipes															# One more toy (`pipes.sh`), because the Internet is a Series of Tubes. (Note You can't use `sudo` with `yay` upfront. Yay will ask you for your sudo password later.)
sudo pacman -S imagemagick													# Manipulate images from the command line. You probably won't use it a whole lot, but there's some cool stuff that is important
mkdir bin																	# Add this directory. It should be added to your `$PATH`. You can use this directory to launch scripts that you write to do tasks
mkdir Projects Downloads Documents Sandbox Music Pictures Videos			# Just some placeholder directories. I should really make them softlinks to their Windows counterpart later.
curl wttr.in																# Check to see if we have curl installed by checking the weather!
sudo pacman -S zsh															# Install Zsh
zsh --version																# Show the version of Zsh. (We're still in Bash, but that will change shortly.)
chsh -l																		# Show a list of shells we can change to.  (You can also see this in `/etc/shells`)
```

OK, we should be ready to do everything in Zsh from now on.

A few things to note
- You'll be asked some questions when you launch Zsh the first time when you run Oh-My-Zsh. I forget what I said, most of these aesthetic. There's probably a tutorial about it on YouTube.
- You may be asked some questions to get Powerlevel10K working (at least for Oh-My-Zsh), if not, run `p10k`.
- If things don't have color when you run `pacman -Ss`, go into the `/etc/pacman.conf` file and uncomment the line that says `Color`.  Visually, this helps out tremendously.
- We could have changed the shell to Zsh using `chsh -s $(which zsh)`, but there was a problem getting that done. Fortunately we can do this with Oh-My-Zsh

```bash
sh -c "$(curl -fsSL http://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" 	# Install Oh-My-Zsh.  (I should have used `yay -S oh-my-zsh-git` but this works just as well.)  (If it asks if you want to change the default shell to Zsh, say yes!)
yay -S --noconfirm zsh-theme-powerlevel10k-git											# Install the powerlevel10k them for zsh.
echo 'source /usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-theme' >> ~/.zshrc	# Use the Powerlevel10K theme in Zsh. (You could use it in Bash too, but I'm not going to do that.)
exec zsh																				# Restart zsh
p10k configure																			# Configure the Powerlevel10k prompt.
sudo pacman -S tmux																		# Install the terminal multiplexer. (We'll have some basic stuff set up in `~/.tmux.conf`)
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm						# Install the TMUX plugin manager.
sudo pacman -S powerline																# Install powerline. The command to enable it for tmux should be in `~/.tmux.conf`.
sudo pacman -S lsd																		# Use lsd (not that LSD! This one make the ls command look cool.) (I added commands to ~/.bash_aliases to use it.)
sudo pacman -S jq																		# Command-line JSON processor. This will be useful later. (There's also `hq` and `yq`, but I haven't tried those yet.)
sudo pacman -S neovim																	# Neovim is something I'm adding. It's basically a text editor based on Vim, but all the plugins are written in Lua. This should also install Lua.
sudo pacman -S python-neovim															# Python 3 plugin support for Neovim
sudo pacman -S zsh-autosuggestions														# Enable auto suggestions in Zsh
sudo pacman -S zsh-syntax-highlighting													# Enable syntax highlighting. You will need to add a line to to bottom of your `~/.zshrc` file.
```

To Activate `zsh-syntax-highlighting`, add the following line to the end of `~/.zshrc`

```bash
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
```

My Github repo should contain
- `~/.bash_aliases`
- `~/.tmux.conf`
- `~/.bashrc`
- `~/.zshrc`
- `~/.p10k.zsh`

You should also run VS Code from this environment for the first time such that both applications become familiar with each other.

```bash
code .			# That is "code" space "period"
```

This will install what WSL and VS Code needs to work with each other.

> TODO: How do I set WSL/Arch as the default terminal for VS Code?

Anything else, I'll probably tack on here later.  I do have some dotfiles you can download to run some other tasks.

Congratulations! You're ready to code like a pro!

## Taskwarrior (optional)
There's one thing I would suggest doing if you are doing software development: Install [taskwarrior](https://taskwarrior.org/).  This is useful because you can write down tasks for things you can do while working on project.  Personally, I'm more of a [Trello](https://trello.com/) person because [Kanban](https://en.wikipedia.org/wiki/Kanban_(development)) is awesome and can be used for more than just computer development. I used it to help me list all the things I need to do when I moved into my apartment a few months ago. It's that versatile.

You could also use something like [Notion](https://www.notion.so/), which as a [Markdown](https://daringfireball.net/projects/markdown/) editor, but in terms of Markdown editors, I prefer [Typora](https://typora.io/) ($15) because it supports [Mermaid](https://mermaid-js.github.io/) where you can generate [UML diagrams](https://www.uml-diagrams.org/) and other charts and uses [MathJax](https://www.mathjax.org/) for [LaTeX](https://www.latex-project.org/) support.  You can also embed HTML and SVG and generate a preview of what the code looks like.

To install Taskwarrior, install the `task` package.

```bash
sudo pacman -S task
```

We can also install a couple of terminal interface programs such as `taskwarrior-tui` and `vit`.  I will add that.

```bash
sudo pacman -S taskwarrior vit
```

There is also a command-line time tracking app called [timewarrior](https://timewarrior.net/) (`timew`) that integrate with `task`.

```bash
sudo pacman -S timew
```

Because we installed powerlevel10k earlier, if we add a task, an item should appear showing how many tasks you have on the right side. If it doesn't show up, you may need to restart ArchWSL or check `~/.p10k.zsh` to make sure that the segment is enabled.
In fact, Powerlevel10k has [many segments](https://github.com/romkatv/powerlevel10k#batteries-included) that can be useful.  You should enable the ones you know that you will need as enabling all of them will be taxing to your system resources.


The first time you run `task` you will be told that a configuration file could not be found and asked if you would like to create a sample one. Say yes to it.
Similarly, if you run `timew` the first time, it will also ask of you would like to create a new database file. Also say yest to that.

I wanted to install [Taskell](https://hackage.haskell.org/package/taskell) (`taskell`), which is a command-line Kanban board written in [Haskell](https://www.haskell.org/), but for some reason, the `taskell` package would not download.  Which is unfortunate considering it could be integrated with Trello and Github and it used Markdown. It is quite unfortunate and will need to be brough up at a later date.

So, this is the part where the Coding Boot Camp picks up. Good luck!