Home > WSL
Slide 1 / 20
🐧

WSL

Windows Subsystem for Linux

📅 3 Minggu - 15 Hari - Complete Guide

Pelajari cara menggunakan Linux di Windows tanpa dual boot. Develop dengan lingkungan Linux asli di Windows!

Overview

Apa itu WSL?

Definisi: Windows Subsystem for Linux (WSL) adalah fitur Windows yang memungkinkan menjalankan environment Linux langsung di Windows tanpa perlu dual boot atau virtual machine.

WSL1 vs WSL2

FiturWSL1WSL2
ArchitectureTranslation layerHyper-V VM
SpeedFast I/ONear native
System CallPartialFull
MemoryFixedDynamic
DockerLimitedNative support
Overview

Tujuan Pembelajaran

Keunggulan WSL

Minggu 1

Dasar-Dasar WSL

HariTopikPraktik
1Instalasi WSL2Enable features, install
2Ubuntu SetupInstall Ubuntu, user config
3Terminal BasicsWSL terminal, Windows Terminal
4File SystemAkses file Windows dari Linux
5NetworkLocalhost, port forwarding
Target Minggu 1: Bisa install WSL2 dan menggunakan terminal Linux.
Minggu 1 - Hari 1

Instalasi WSL2

Cara 1: PowerShell (Rekomendasi)

# Buka PowerShell as Administrator
wsl --install

# Atau install WSL2 saja
wsl --install -d Ubuntu

Cara 2: Manual

# 1. Enable Virtual Machine Platform
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

# 2. Restart komputer

# 3. Set WSL2 sebagai default
wsl --set-default-version 2
Setelah install, Ubuntu akan otomatis terbuka!
Minggu 1 - Hari 2

Ubuntu Setup

Initial Setup

# Saat pertama kali dibuka, buat username dan password
# Username tidak boleh sama dengan Windows username

# Update packages
sudo apt update && sudo apt upgrade -y

Install Essential Tools

# Build tools
sudo apt install -y build-essential curl wget git

# Zsh (opsional)
sudo apt install -y zsh

# Oh My Zsh (opsional)
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Set Default User

# Ubah default user ke user baru
ubuntu config --default-user yourusername
Minggu 1 - Hari 3

Terminal Setup

Windows Terminal (Rekomendasi)

# Install dari Microsoft Store
# Atau download dari GitHub releases

Konfigurasi Windows Terminal

{
    "profiles": {
        "defaults": {
            "colorScheme": "Ubuntu",
            "fontFace": "Cascadia Code"
        },
        "list": [
            {
                "guid": "{...}",
                "name": "Ubuntu",
                "source": "Windows.Terminal.Wsl"
            }
        ]
    }
}

Shortcut Berguna

Minggu 1 - Hari 4

File System

Akses File Windows dari Linux

# Mount Windows drives otomatis di /mnt
ls /mnt/

#Contoh: Akses drive C
ls /mnt/c/Users/YourName/

# Atau gunakan path Windows langsung
cd /mnt/c/Projects/

Akses File Linux dari Windows

# Buka File Explorer dari WSL
explorer.exe .

# Atau ketik di Windows Explorer:
\\wsl$\Ubuntu\home\username\

Best Practices

Catatan: Jangan edit file Linux dari Windows menggunakan aplikasi Windows, bisa menyebabkan corruption!
Minggu 1 - Hari 5

Networking

Localhost Access

# Dari WSL, akses Windows localhost
# Gunakan IP Windows
curl http://$(hostname).local:8080

# Atau gunakan /etc/resolv.conf nameserver
curl http://$(grep nameserver /etc/resolv.conf | head -1 | awk '{print $2}'):8080

Port Forwarding Otomatis

# WSL2 otomatis expose port ke Windows
# Jika di WSL: python -m http.server 8000
# Di Windows akses: http://localhost:8000

Static IP (Opsional)

# Buat /etc/wsl.conf
[network]
generateResolvConf = false

# Edit /etc/resolv.conf dengan IP statis
Minggu 2

WSL Development

HariTopikPraktik
1Node.jsInstall Node, npm, yarn
2Pythonpyenv, venv, pip
3Go & RustInstall Go, Rust
4VS CodeRemote Development
5Git SetupGit config, SSH keys
Target Minggu 2: Setup complete development environment.
Minggu 2 - Hari 1

Node.js Development

Install Node.js

# Cara 1: Via apt
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs

# Cara 2: Via nvm (rekomendasi)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
nvm install 20
nvm use 20

Install npm packages

# Global
npm install -g typescript nodemon pm2

# Project lokal
npm init -y
npm install express

Yarn

# Install yarn
npm install -g yarn

# Install pnpm
npm install -g pnpm
Minggu 2 - Hari 2

Python Development

Install Python

# Install Python 3.11
sudo apt install -y python3.11 python3.11-venv python3-pip

# Set default python3
python3 --version

pyenv (įŽĄį† Multiple Python Versions)

# Install pyenv
curl https://pyenv.run | bash

# Install Python tertentu
pyenv install 3.11.0
pyenv global 3.11.0

Virtual Environment

# Buat venv
python3 -m venv myenv

# Activate
source myenv/bin/activate

# Install packages
pip install flask fastapi django
Minggu 2 - Hari 3

Go & Rust

Install Go

# Download dan install Go
wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin

# Verify
go version

Install Rust

# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Activate
source $HOME/.cargo/env

# Verify
rustc --version
cargo --version

VS Code Extensions

# Install di VS Code (Remote WSL)
# - Go
# - Rust Analyzer
# - Python
# - Node.js
Minggu 2 - Hari 4

VS Code Remote Development

Setup Remote Development

# 1. Install VS Code
# https://code.visualstudio.com/

# 2. Install extension "Remote - WSL"
# Dari VS Code Extensions (Ctrl+Shift+X)

Buka Project di WSL

# Cara 1: Dari VS Code
# - Tekan F1
# - Ketik "WSL: New Window"
# - Pilih "New Window in WSL"

# Cara 2: Dari terminal WSL
code .
code /path/to/project

Fitur Remote Development

Tips: Install extensions di WSL, bukan di Windows!
Minggu 2 - Hari 5

Git & SSH Setup

Git Configuration

# Setup Git
git config --global user.name "Your Name"
git config --global user.email "[email protected]"

# Line endings (penting untuk Windows!)
git config --global core.autocrlf input

Generate SSH Key

# Generate SSH key
ssh-keygen -t ed25519 -C "[email protected]"

# Add ke ssh-agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

Add SSH Key ke GitHub

# Copy public key
cat ~/.ssh/id_ed25519.pub
# Atau
clip.exe < ~/.ssh/id_ed25519.pub

# Paste ke GitHub > Settings > SSH Keys
Tips: Gunakan SSH bukan HTTPS untuk avoid password prompts!
Minggu 3

Advanced WSL

HariTopikPraktik
1DockerDocker Desktop, Docker di WSL2
2Multiple DistrosInstall multiple Linux
3PerformanceWSL tuning
4Backup & MigrateExport/Import
5TroubleshootingCommon issues
Minggu 3 - Hari 1

Docker di WSL2

Cara 1: Docker Desktop

# Install Docker Desktop
# https://www.docker.com/products/docker-desktop/

# Enable WSL2 backend di Docker Desktop settings
# WSL2-based engine akan aktif otomatis

# Test Docker di WSL
docker --version
docker ps

Cara 2: Docker Tanpa Docker Desktop

# Install Docker di WSL
sudo apt install -y docker.io

# Start Docker service
sudo service docker start

# Add user ke docker group
sudo usermod -aG docker $USER

# Logout dan login kembali

Docker Compose

# Install Docker Compose
sudo apt install -y docker-compose

# Atau
sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Minggu 3 - Hari 2

Multiple Distros

Install Distro Lain

# List available distros
wsl --list --online

# Install distro lain
wsl --install -d Debian
wsl --install -d Kali-Linux
wsl --install -d Arch-Linux

Manage Multiple Distros

# List semua WSL
wsl --list -v

# Set default
wsl --set-default Ubuntu

# Switch ke distro lain
wsl -d Debian
wsl -s Kali-Linux

Run Commands di Distro Tertentu

# Tanpa masuk ke shell
wsl -d Ubuntu -- python3 --version
wsl -d Debian -- apt update
Tips: Beda distro = Beda environment. Install sesuai kebutuhan!
Minggu 3 - Hari 3

WSL Performance

WSL Configuration

# Buat /etc/wsl.conf
sudo nano /etc/wsl.conf

[automount]
enabled = true
options = "metadata,umask=22,fmask=11"
mountFsTab = false

[interop]
enabled = true
appendWindowsPath = true

[network]
generateResolvConf = true

Memory & CPU Limits

# Buat .wslconfig di Windows (C:/Users/YourName/)
[wsl2]
memory=4GB
processors=2
swap=2GB
localhostForwarding=true

Disable Windows Features yang Tidak Perlu

# Non-aktifkan antivirus scanning untuk WSL folder
# Tambahkan ke Windows Security > Exclusions
\\wsl$\
Catatan: Setelah edit .wslconfig, jalankan: wsl --shutdown
Final

Selamat!

Anda telah menyelesaikan WSL Learning Curriculum!

Next Steps

Referensi:
- docs.microsoft.com/en-us/windows/wsl
- aka.ms/wsl2
- GitHub WSL

Kuis: WSL

Apa kepanjangan WSL?

WSL2 menggunakan arsitektur apa?

Command apa untuk install Linux di WSL?