An Interest In:
Web News this Week
- April 2, 2024
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
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 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 ArchWSlArch.exe# Root passwordpasswd# Enter a strong and complicated password# to keep your ArchWSL installation# secure# Setup sudoers fileecho "%wheel ALL=(ALL) ALL" > /etc/sudoers.d/wheel# Add new useruseradd -m -G wheel -s /bin/bash {username}# Password for new userpassword {username}# Exit out of ArchWSLexit# Change default userArch.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 LinuxArch.exe# Initialize keyringsudo pacman-key --initsudo pacman-key --populate# Update pacman database and programssudo pacman -Syu# Install archlinux-keyringsudo pacman -S archlinux-keyring# Install neovim to check if everything workssudo 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 supportsbash
scripting.Switch to fish shell using the following command
# Switch to fish shellchsh -s /usr/local/bin/fish
- Make a
.config
directory for configurations
mkdir .config# Make fish config directorymkdir .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-256coloralias g gitalias grep rgcommand -qv nvim && alias vim nvimalias drop_cache="sudo sh -c \"echo 3 >'/proc/sys/vm/drop_caches' && swapoff -a && swapon -a && printf '
%s
' '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"endset -gx EDITOR nvimset -gx PATH bin $PATHset -gx PATH ~/bin $PATHset -gx PATH ~/.local/bin $PATHset -gx PATH node_modules/.bin $PATHset LOCAL_CONFIG (dirname (status --current-filename))/config-local.fishif test -f $LOCAL_CONFIG source $LOCAL_CONFIGend
- Install fisher for plugins and a few plugins we'll need
# Install fishercurl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher# NVMfisher 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 NodeJSnvm install 16# Use NodeJS LTSnvm use 16
- Add the following lines in config.fish for NVM to work properly
begin nvm use 16end &> /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.
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.
Original Link: https://dev.to/abhimadhukalya/setting-up-wsl-for-beginners-346l
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To