ArchLinux config on WSL2 to developers
Tags: wsl2, linux, archlinux, programming
Published: 2022-11-21 16:27:22

> [Versão em português](https://dev.to/dchueri/configurando-o-archlinux-com-wsl-2-para-devs-393n)

In the last few days, I needed to format my equipment again and I felt the need to have documentation to speed up this part of configuring my development environment. I use some apps in my day-to-day life that prevent me from using only Linux, for a while I used dual-boot, but the need to restart the PC for some quick code changes made me look for another alternative, in this case, WSL.

The initial idea was just to document to facilitate my configuration process, but as lemonade comes from lemon, I decided to share it with you here. I'm not going to sound deep about the WSL or the reasons for each choice, but I'm open to suggestions and dialogues with anyone interested.

If you don't know what WSL is or are looking for more information about it, follow the link to the official Microsoft documentation (numerous articles can be found by a quick search):

[What is the Windows Subsystem for Linux?](https://learn.microsoft.com/en-us/windows/wsl/about)

## Installing WSL

If you have not yet installed WSL on your Windows, enter the following command in Windows PowerShell:

```bash
wsl --install
```

[Install WSL | Microsoft Learn](https://learn.microsoft.com/en-us/windows/wsl/install#install-wsl-command)

## Windows Terminal

I prefer to use Windows Terminal for two main reasons: customization and taking advantage of some Linux commands. Installation is simple and can be done using the link below:

[Windows Terminal - Microsoft Store Apps](https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701?hl=en-us)

## Install Arch

This version of Arch that I use is very lightweight compared to other options (like Manjaro):

[https://github.com/yuk7/ArchWSL](https://github.com/yuk7/ArchWSL)

Just extract the files to a preferred folder and run the Arch file, which will start the installation.

## Creating a user

Once the installation is complete, it's time to configure a user and make it the default at startup, avoiding using the root user. Just follow the commands below, remembering to replace `{username}` with the desired _name_:

```bash
echo "%wheel ALL=(ALL) ALL" > /etc/sudoers.d/wheel
```

```bash
useradd -m -G wheel -s /bin/bash {username}
```

```bash
passwd {username}
```

Now to set the created user as default, close Arch and open your terminal in the folder where the Arch.exe file is and enter the following command:

```bash
.\Arch.Exe config --default-user {username}
```

[How to Setup | ArchWSL official documentation](https://wsldl-pg.github.io/ArchW-docs/How-to-Setup/#set-up-the-default-user)

## Updating distro packages

Before updating we need to initialize pacman's keyring:

```bash
sudo pacman-key --init
```

And also perform the initial configuration of the keys with the:

```bash
sudo pacman-key --populate
```

```bash
sudo pacman -Sy archlinux-keyring
```

```bash
sudo pacman -Syu
```

[pacman/Package signing - ArchWiki](https://wiki.archlinux.org/title/Pacman/Package_signing)

[Initialize keyring | ArchWSL official documentation (wsldl-pg.github.io)](https://wsldl-pg.github.io/ArchW-docs/How-to-Setup/#initialize-keyring)

## Package managers

I will initially install the YARN and NPM managers:

```bash
sudo pacman -S yarn npm
```

As [AUR](https://wiki.archlinux.org/title/Arch_User_Repository) manager I use [Yay](https://github.com/Jguer/yay):

```bash
sudo pacman -S --needed git base-devel
```

Finally, with *“Rust”* package to use *“cargo”*:

```bash
sudo pacman -S rust
```

To install Yay it will be necessary to clone the repository, as after installation the files will no longer be used I choose to create a temporary folder to facilitate deletion later:

```bash
mkdir tmp
```

```bash
cd tmp
```

Now just clone the repository and build it with `makepkg`:

```bash
git clone https://aur.archlinux.org/yay.git
```

```bash
cd yay
```

```bash
makepkg -si
```

[Jguer/yay: Yet another Yogurt - An AUR Helper written in Go (github.com)](https://github.com/Jguer/yay#installation)

### Z Shell

Install ZSH:

```bash
yay -S zsh
```

## Customizing the Terminal

### Changing the terminal theme

[Windows Terminal Themes](https://windowsterminalthemes.dev/) has several themes ready for your terminal, just choose the theme of your choice and click on the “*Get theme*” button, and with that selected theme will be copied to your clipboard. My favorite theme is [Dracula](https://windowsterminalthemes.dev/?theme=Dracula).

Just go back to the terminal, use the shortcut `Ctrl + ,` to open the *Configurations*, and click on *Open JSON file* in the lower left corner.


![Print screen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1s0r2jmfx7ks4pdrwdhj.jpg)

After the last theme (themes are inside the "*schemes*" array), put a `,` and paste the chosen theme. Save and close the file.

> **Note:** If you "break" the JSON file, while the terminal is open it may work normally, but when restarting it you will find an error similar to [this](https://i.imgur.com/Dp8w5WD.png). If this is tolerated, just click “OK”, open the JSON file again, check the syntax and save the file.

Return to the *Settings screen,* open the Arch profile, under “*Additional settings”* and click on “*Appearance”*. Now just change the “*Color Scheme*” to the desired option. Click “*Save*” and close the settings.

### Customizing ZSH

To change the ZSH theme I use [Powerlevel10k](https://github.com/romkatv/powerlevel10k):

```bash
yay -S --noconfirm zsh-theme-powerlevel10k-git
```

```bash
echo 'source /usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-theme' >>~/.zshrc
```

```bash
chsh -s /usr/bin/zsh
```

Restart the terminal.

### Font

After installing Powerlevel10k, when you start the terminal again, a settings screen will appear where some symbols should be displayed:

![Print of terminal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lzc52918hwliw624th5j.png)

> If you are unable to view the displayed symbols, just install one of the calls [Nerd Fonts](https://www.nerdfonts.com/font-downloads) and change the Arch profile font in “*Additional Settings*” > “*Appearance*” > “*Font type*”.

When you want to access the Powerlevel10k configuration screen again, just type:

```bash
p10k configure
```

### Plugins

In my case, I usually use the following plugins:

- [ZSH Autosuggestions](https://github.com/zsh-users/zsh-autosuggestions): which does an autocomplete based on my command history;

- [exa](https://github.com/ogham/exa): serves as an alternative to “*ls*”; and

- [bat](https://github.com/sharkdp/bat): alternative “*cat*”.

```bash
mkdir .zsh
```

```bash
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
```

```bash
cargo install bat exa
```

Open the .zshrc file in your preferred editor and add to the end of the file:

```bash
code .zshrc
```

```bash
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
alias ls="exa --icons"
alias bat="bat --style-auto"
```

## NVM

For managing node versions I use [NVM](https://github.com/nvm-sh/nvm):

```bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
```

## Docker

It is necessary to have Docker Desktop installed on Windows. With that, just type in the terminal:

```bash
yay -S docker
```

And finally, enable the Arch distro in the _Resources_ of Docker Desktop.

## And is this

Throughout the article, I tried to provide some useful links so that each one can perform the best configuration as appropriate. As said at the beginning, feel free to make suggestions, as well as indicate any errors that occurred during the process and also share your preferences with others.