Skip to content

Instantly share code, notes, and snippets.

@TadejPolajnar
Last active March 5, 2024 06:28
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save TadejPolajnar/9708401ef13e443c95cea0ece2a215f0 to your computer and use it in GitHub Desktop.
Save TadejPolajnar/9708401ef13e443c95cea0ece2a215f0 to your computer and use it in GitHub Desktop.
Windows WSL 2 terminal setup

Windows WSL 2 terminal setup

Prerequisites

Windows 10 version 2004 (Build 10941) or higher.

Enabled Windows Subsystem for Linux feature. To enable following enter in Powershell

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Enabled Virtualization feature. (Required for WSL2)

Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

Ubuntu setup

Download Ubuntu from Microsoft Store

Open it and finish the installation process

To disable password (Optional, not recomended)

# Open
sudo nano /etc/sudoers.d/YOUR_USERNAME
# Example
YOUR_USERNAME ALL=(ALL) NOPASSWD:ALL

In PowerShell check if WSL is installed: wsl --list --verbose

If version is 1 convert it to 2 by entering:

wsl --set-version <distro-name> 2
# Example
wsl --set-version Ubuntu 2

If it throws an error install linux kernel update package

Terminal setup

Download Windows terminal from Microsoft store

Open settings and set default profile to Ubuntu

Update Ubuntu terminal

sudo apt update
sudo apt upgrade

Install build tools

sudo apt install build-essential

Git setup

Install git

sudo apt install git

Set end of line

git config --global core.autocrlf input

Node & NPM setup

Install nvm:

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

Restart your terminal

To check if installation was successfull

command -v nvm

It should return nvm

If it does not return anything load nvm

[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh

If nvm is not defined each time you open Terminal

# Open zsh config
sudo nano ~/.zshrc
# Add this lines at the bottom
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

Install node

nvm install node

Restart terminal

Install your node version

nvm install <node version>
# Example
nvm install 12

Docker

Install and update dependencies

sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common

Add Dockers’s official GPG-key.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Verify this by running:

sudo apt-key fingerprint 0EBFCD88
#Output: 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88

Add the Docker repository to your list of repositories.

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Update the list of repositories again and install Docker CE.

sudo apt update
sudo apt install docker-ce

Start docker manually

sudo service docker start

Verify Docker by booting up their hello-world container.

sudo docker run hello-world

Docker compose

Install current stable release.

sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Make the file executable.

sudo chmod +x /usr/local/bin/docker-compose

Verify the installation.

docker-compose --version
# output: docker-compose version 1.24.0, build 0aa59064

Docker Desktop

Download Docker Desktop from official webpage.

Run command to verify docker container is working

docker run -dp 80:80 docker/getting-started

You should see new container inside Docker Desktop

Yarn setup

Add their gpg key

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

Add their repository

echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

Install yarn, --no-install-recommends flag skips node installation

sudo apt update
sudo apt install --no-install-recommends yarn

Verify installation

yarn --version

ZSH setup

Install zsh

sudo apt install zsh

Set default shell to zsh

chsh -s $(which zsh)

Oh My ZSH setup

Install Oh My ZSH

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Follow the instructions

FAQ

Application won't reload on change

Make sure your project is inside home directory not mnt

NVM command "command -v nvm" doesn't return anything

If it does not return anything load nvm

[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh

If nvm is not defined each time you open Terminal

# Open zsh config
sudo nano ~/.zshrc
# Add this lines at the bottom
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Yarn ERROR: There are no scenarios; must have at least one

Remove cmdtest package

sudo apt remove cmdtest

Install yarn again

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt install yarn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment