Setting up WSL as a developer environment (for beginners)

Last time, we set up Windows Terminal and Powershell to suite our needs for a proper developer environment. In this post, we will enable and set up Windows Subsystem for Linux (WSL). It is a compatibility layer to help us run linux binary executables n…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Abhigyan Madhukalya

Last time, we set up Windows Terminal and Powershell to suite our needs for a proper developer environment. In this post, we will enable and set up Windows Subsystem for Linux (WSL). It is a compatibility layer to help us run linux binary executables natively on Windows.

Ingredients:

  • Windows Subsystem for Linux (WSL)
  • Fish shell
  • Neovim
  • NodeJS
  • zoxide
  • Fisher (plugin manager for Fish shell)
  • packer (plugin manager for Neovim)
  • ArchWSL (Arch Linux for WSL)

Enable Windows Subsystem for Linux

  • WSL by default is disabled for everyday Windows users so we have to enable it by ourselves.

  • To enable WSL, enter the following command in a Powershell tab in Windows Terminal.

  sudo Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
  # WSL2 (This tutorial will use WSL2)
  wsl --set-default-version 2

Install a Linux distro

  • We could install a distro like Ubuntu directly using the wsl command but Ubuntu is not good distro to use for developing or programming according to me.

  • I use Arch Linux from the yuk7/ArchWSL repository. Arch Linux is a bleeding-edge distro, meaning all packages are up-to-date with their parent repo at any given moment.

  • To install Arch Linux for WSL, enter the following commmands

  scoop add bucket extras
  scoop install archwsl

  # Open Arch Linux for the first time
  Arch.exe

Setup root password and default user

  • Unlike Ubuntu which gives you a prompt to setup the root password and default user, in Arch Linux you have to do it by yourself.

  • To setup root password and default user, enter the following commands that are taken from the ArchWSL website

# Boot into ArchWSl
Arch.exe

# Root password
passwd

# Enter a strong and complicated password
# to keep your ArchWSL installation
# secure
# Setup sudoers file

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

# Add new user
useradd -m -G wheel -s /bin/bash {username}

# Password for new user
password {username}

# Exit out of ArchWSL
exit

# Change default user
Arch.exe config --default-user {username}

  • Refer to documentation if you don't understand a step.

  • Restart your computer to confirm changes

Initialize keyring (IMPORTANT STEP)

  • This step is necessary for pacman (Arch Linux package manager) to work

  • Enter the following commands to initialize keyring

# Boot into Arch Linux
Arch.exe

# Initialize keyring
sudo pacman-key --init
sudo pacman-key --populate

# Update pacman database and programs
sudo pacman -Syu

# Install archlinux-keyring
sudo pacman -S archlinux-keyring

# Install neovim to check if everything works
sudo pacman -S neovim

Install packages for this tutorial

sudo pacman -S fish neovim base-devel git ripgrep exa

The packages we installed are:

  • Neovim: Terminal text editor
  • Fish: command-line shell
  • base-devel: Group of packages to make life a little easier
  • ripgrep: grep but faster
  • exa: ls but prettier

Setup Fish Shell

  • fish is a smart and user-friendly command line fish is a smart and user-friendly command line
    shell for Linux, macOS, and the rest of the family, with built-in autosuggesstions and syntax highlighting.

  • You can also use zsh which is POSIX compliant and supports bash scripting.

  • Switch to fish shell using the following command

# Switch to fish shell
chsh -s /usr/local/bin/fish
  • Make a .config directory for configurations
mkdir .config
# Make fish config directory
mkdir .config/fish
  • Make a config.fish in .config/fish directory
touch .config/fish/config.fish
  • Edit config.fish to your liking
set fish_greeting ""

set -gx TERM xterm-256color

alias g git
alias grep rg
command -qv nvim && alias vim nvim
alias drop_cache="sudo sh -c \"echo 3 >'/proc/sys/vm/drop_caches' && swapoff -a && swapon -a && printf '\n%s\n' 'Ram-cache and Swap Cleared'\""

if type -q exa
  alias ls='exa -l -g -a --icons --group-directories-first'
  alias ll='exa -l -g --icons --group-directories-first'
  alias lt="ll --tree --level=2"
end

set -gx EDITOR nvim
set -gx PATH bin $PATH
set -gx PATH ~/bin $PATH
set -gx PATH ~/.local/bin $PATH
set -gx PATH node_modules/.bin $PATH

set LOCAL_CONFIG (dirname (status --current-filename))/config-local.fish
if test -f $LOCAL_CONFIG
 source $LOCAL_CONFIG
end
  • Install fisher for plugins and a few plugins we'll need
# Install fisher
curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher

# NVM
fisher install jorgebucaran/nvm.fish

# Tide (Best prompt for fish, inspired by powerlevel10k)
fisher install IlanCosman/tide@v5
  • Install NodeJS using NVM
# Install LTS Version of NodeJS
nvm install 16

# Use NodeJS LTS
nvm use 16
  • Add the following lines in config.fish for NVM to work properly
begin
  nvm use 16
end &> /dev/null

Configure Neovim

Configuring Neovim takes a long time and can have its own blog post. Read @craftzdog post on Neovim Configuration to setup Neovim for developing.

You can also fork my dotfiles repository and use its configurations for yourself.

abhigyanmadhukalya (Abhigyan Madhukalya) · GitHub

Self-taught Developer from India. abhigyanmadhukalya has 10 repositories available. Follow their code on GitHub.

favicon github.com

This concludes the second post in the series 'Turn Windows into a proper dev environment'. Now we have a proper UNIX-developer environment supported by a proper Windows-developer environment.


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Abhigyan Madhukalya


Print Share Comment Cite Upload Translate Updates
APA

Abhigyan Madhukalya | Sciencx (2022-10-02T04:14:09+00:00) Setting up WSL as a developer environment (for beginners). Retrieved from https://www.scien.cx/2022/10/02/setting-up-wsl-as-a-developer-environment-for-beginners/

MLA
" » Setting up WSL as a developer environment (for beginners)." Abhigyan Madhukalya | Sciencx - Sunday October 2, 2022, https://www.scien.cx/2022/10/02/setting-up-wsl-as-a-developer-environment-for-beginners/
HARVARD
Abhigyan Madhukalya | Sciencx Sunday October 2, 2022 » Setting up WSL as a developer environment (for beginners)., viewed ,<https://www.scien.cx/2022/10/02/setting-up-wsl-as-a-developer-environment-for-beginners/>
VANCOUVER
Abhigyan Madhukalya | Sciencx - » Setting up WSL as a developer environment (for beginners). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/10/02/setting-up-wsl-as-a-developer-environment-for-beginners/
CHICAGO
" » Setting up WSL as a developer environment (for beginners)." Abhigyan Madhukalya | Sciencx - Accessed . https://www.scien.cx/2022/10/02/setting-up-wsl-as-a-developer-environment-for-beginners/
IEEE
" » Setting up WSL as a developer environment (for beginners)." Abhigyan Madhukalya | Sciencx [Online]. Available: https://www.scien.cx/2022/10/02/setting-up-wsl-as-a-developer-environment-for-beginners/. [Accessed: ]
rf:citation
» Setting up WSL as a developer environment (for beginners) | Abhigyan Madhukalya | Sciencx | https://www.scien.cx/2022/10/02/setting-up-wsl-as-a-developer-environment-for-beginners/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.