DEV Community

Cover image for How to install Arch Linux for WSL
Jason Charney
Jason Charney

Posted on • Edited on

How to install Arch Linux for WSL

UPDATE! 10/11/2022 This post has been deprecated. See this post 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.

You need to install something called 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.

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
Enter fullscreen mode Exit fullscreen mode

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.

DISM /Online /Enable-Feature /All /FeatureName:Microsoft-Hyper-V
Enter fullscreen mode Exit fullscreen mode

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

From the Microsoft Store App, you should install the Windows Terminal application and also Visual Studio Code. If you have Windows 11, you should already have Windows Terminal.

Get a Windows Installer

You should install either Chocolatey or Scoop so you can download some stuff in the command line, especially the NerdFonts 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

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"
Enter fullscreen mode Exit fullscreen mode

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.

scoop update
Enter fullscreen mode Exit fullscreen mode

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.

scoop bucket add nerd-fonts
Enter fullscreen mode Exit fullscreen mode

Next install the font packages

scoop install Meslo-NF Meslo-NF-Mono Hack-NF Hack-NF-Mono FiraCode-NF FiraCode-NF-Mono FiraMono-NF FiraMono-NF-Mono
Enter fullscreen mode Exit fullscreen mode

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.

wsl --set-version 2
scoop bucket add extras
scoop install archwsl
Enter fullscreen mode Exit fullscreen mode

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.

Arch.exe
Enter fullscreen mode Exit fullscreen mode

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.

[root@crystal]# passwd
Enter fullscreen mode Exit fullscreen mode

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.

[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
Enter fullscreen mode Exit fullscreen mode

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

Arch.exe config --default-user jrcharney                    # Note: Use your username not mine!
Enter fullscreen mode Exit fullscreen mode

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

[jrcharney@crystal]$
Enter fullscreen mode Exit fullscreen mode

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.

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`)
Enter fullscreen mode Exit fullscreen mode

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
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.
Enter fullscreen mode Exit fullscreen mode

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

source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
Enter fullscreen mode Exit fullscreen mode

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.

code .          # That is "code" space "period"
Enter fullscreen mode Exit fullscreen mode

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. 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 person because Kanban 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, which as a Markdown editor, but in terms of Markdown editors, I prefer Typora ($15) because it supports Mermaid where you can generate UML diagrams and other charts and uses MathJax for LaTeX 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.

sudo pacman -S task
Enter fullscreen mode Exit fullscreen mode

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

sudo pacman -S taskwarrior vit
Enter fullscreen mode Exit fullscreen mode

There is also a command-line time tracking app called timewarrior (timew) that integrate with task.

sudo pacman -S timew
Enter fullscreen mode Exit fullscreen mode

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 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 (taskell), which is a command-line Kanban board written in Haskell, 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!

Top comments (1)

Collapse
 
askir profile image
hilga007

Man, I broke my Arch install on my secondary list and was trying to find a guide to use arch-chroot to fix it. Stumbled upon this post here thanks to the BingGPT search referencing this as my solution instead.

The only major difference between the time of writing and my time of posting is that Arch WSL is available through the Windows Store as is WSL.... but then everything else is mostly the same.

(Though I went the Powershell route for fun wtih 7.3.6 and everything worked as expected! At the end: I did wsl.exe --update so that it would stay updated along with the Store version)