Skip to content

Instantly share code, notes, and snippets.

@ld100
Last active April 27, 2024 18:05
Show Gist options
  • Save ld100/3376435a4bb62ca0906b0cff9de4f94b to your computer and use it in GitHub Desktop.
Save ld100/3376435a4bb62ca0906b0cff9de4f94b to your computer and use it in GitHub Desktop.
Steps for setting up Arch Linux on WSL2

Migrating from Ubuntu on WSL to ArchLinux on WSL2

Obsolete notice

This document was created back in 2020 and might not be actual nowadays. It is not supported anymore, so use thise information at your own risk.

Upgrading to WSL 2

  • Download WSL2 Kernel
  • run wsl --set-default-version 2 in windows command line, so that all future WSL machine will use WSL2.

Installing Arch Linux

Basic installation

  • Download ArchWSL installer zip, pick a folder (for example, c:\archlinux) for Arch Linux and run installer .exe in that folder.

Initialize package manager

  • Add custom pacman repository with additional packages: nano /etc/pacman.conf Then add following to the bottom:
[archlinuxfr]
SigLevel = Never
Server = http://repo.archlinux.fr/$arch
  • Refresh Pacman GPG keys:
pacman-key --init
pacman-key --populate
pacman-key --refresh-keys
pacman -Sy archlinux-keyring
  • Run pacman -Syyu to update all packages to the latest versions

Install zsh, optional

  • Install zsh: pacman -S zsh

Create a user

  • Add a sudo group: groupadd sudo
  • Enable sudoers: nano /etc/sudoers and uncomment lines %wheel ALL=(ALL) NOPASSWD: ALL and %sudo ALL=(ALL) ALL
  • Add new admin user: useradd -m -G wheel,sudo -s /bin/zsh <username>, use -s /bin/bash if you want bash instead of zsh.
  • Set password for the new user: passwd <username>
  • Run Windows command shell, go to the directory with Arch Linux, run Arch.exe config --default-user <username>. Now you have basic ArchLinux with user.

Install AUR helper

  • Just follow How to Install Yay AUR Helper in Arch Linux and Manjaro guide:
  • sudo pacman -S git openssh
  • sudo pacman -S base-devel - when asked question on fakeroot and fakeroot-tcp choose to leave fakeroot-tcp and not install fakeroot
  • git clone https://aur.archlinux.org/yay-git.git
  • cd yay-git
  • makepkg -si
  • Run yay -Syu to update all AUR packages and reinstall fakeroot-tcp (will install the latest version)
  • Remove the leftovers: rm -rf ~/yay-git

Goodies

  • Install useful console tools: sudo pacman -S mc wget htop pv ccze

Preserving config files from previous WSL installation

Copy .ssh, .kube, .aws from original installation home directory to the Arch WSL2 one.

Fix file permissions for SSH keys, run from the home directory:

chmod 0644 .ssh/id_rsa.pub
chmod 0600 .ssh/id_rsa

Installing additional software

Install Kubernetes

sudo pacman -S kubectl kubectx

Install Docker

Uninstall Windows docker to prevent potential naming conflicts.

sudo pacman -S docker docker-compose

Use wsl2-docker-start scripts to run docker exposed to Windows:

git clone git@github.com:imjonos/wsl2-docker-start.git
cd wsl2-docker-start
chmod +x docker-start prepare-hosts
sudo cp docker-start prepare-hosts /usr/local/bin

In Windows you should make sure C:\Windows\System32\drivers\etc\hosts file has write access for your user. Always run docker in a dedicated terminal tab using docker-start

ld100 dotfiles & zsh config

git clone https://github.com/ld100/dotfiles.git ~/.dotfiles
zsh ~/.dotfiles/install.sh

Install programming languages

sudo pacman -S ruby nodejs python go crystal php jre-openjdk-headless

Installing protocol buffers

Main binaries/libraries: sudo pacman -S protobuf protobuf grpc grpc-cli

gRPC for Python and PHP: sudo pacman -S python-grpcio php-grpc

gRPC & Protobuf for Go: yay -S protobuf-go protoc-gen-go-grpc

gRPC & Protobuf for Ruby: gem install google-protobuf grpc grpc-tools

Setting ArchLinux as default WSL

Just run wsl --set-default Arch in windows command shell.

Accessing WSL from Windows

All WSL machines are available in Windows Explorer on \\wsl$\ URL, Arch linux is: \\wsl$\Arch. For additional convenience you could map \\wsl$\Arch to a 1-Leter Windows disk share, for example having Z:\ pointing to \\wsl$\Arch

Copy link

ghost commented Jan 3, 2022

What is the correct way to uninstall this?

@stoyanovgeorge
Copy link

I have managed to install the repo, but for example the ping doesn't work. More so, when you check /.ssh/ directory, there are some existing public/private keys and a config file with an already configured server. I can only assume there are other files, which are customized by the creator.

@akc3n
Copy link

akc3n commented Feb 22, 2022

Hi @ld100 quick question, what exactly is this custom pacman repository used for in your instructions? I did have this added to another setup I did on different PC. But I do recall it was SO SLOW! So I was just curious about it.

I also have another alternative setup ( on a different laptop as well) as instructed in this comment

However, I am adding this ArchWSL again on a new reinstalled Windows 10 PC right now. And wanted to ask about that custom pacman repo you mentioned. Thank you.

@ld100
Copy link
Author

ld100 commented Feb 22, 2022

@akc3n I don't remember unfortunately. It was couple years ago and I'm not using Arch Linux for a long time since then.

@akc3n
Copy link

akc3n commented Feb 25, 2022

@ld100 okay, no worries, thanks for your reply.

@oniony
Copy link

oniony commented May 12, 2022

@groboclown your solution is great, but how to set a default user, I don't want root to be the default user and it bothers me to run su all the time

Within the WSL distro, edit or create /etc/wsl.conf and add the following:

[user]
default=someuser

Before you do that, ensure you set a password for root or your regular account has sudo access. (If you do find yourself without root capabilities, you can run wsl --user root to get back in as root.)

@NormTurtle
Copy link

image
cant add user 😭

@piotr25691
Copy link

Just use https://github.com/sorah/subsystemctl

Update December 5th 2022: Since some time ago, WSL2 now supports the usage of systemd natively, no need to install additional software to enable it.

@nnbveh
Copy link

nnbveh commented Sep 13, 2023

Hello. Could you please tell me how to UNINSTALL arch from WSL? thanks!

@ItamarOliveira
Copy link

in powershell command prompt you can use
wsl --unregister arch

or go to Settings, applications, and uninstall there.

@caamittiwari
Copy link

we unable to run postgres on archlinux on wsl2 i am get error psql: error: connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
please help me where iam going wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment