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!
| Fitur | WSL1 | WSL2 |
|---|---|---|
| Architecture | Translation layer | Hyper-V VM |
| Speed | Fast I/O | Near native |
| System Call | Partial | Full |
| Memory | Fixed | Dynamic |
| Docker | Limited | Native support |
| Hari | Topik | Praktik |
|---|---|---|
| 1 | Instalasi WSL2 | Enable features, install |
| 2 | Ubuntu Setup | Install Ubuntu, user config |
| 3 | Terminal Basics | WSL terminal, Windows Terminal |
| 4 | File System | Akses file Windows dari Linux |
| 5 | Network | Localhost, port forwarding |
# Buka PowerShell as Administrator wsl --install # Atau install WSL2 saja wsl --install -d Ubuntu
# 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
# Saat pertama kali dibuka, buat username dan password # Username tidak boleh sama dengan Windows username # Update packages sudo apt update && sudo apt upgrade -y
# 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)"
# Ubah default user ke user baru ubuntu config --default-user yourusername
# Install dari Microsoft Store # Atau download dari GitHub releases
{
"profiles": {
"defaults": {
"colorScheme": "Ubuntu",
"fontFace": "Cascadia Code"
},
"list": [
{
"guid": "{...}",
"name": "Ubuntu",
"source": "Windows.Terminal.Wsl"
}
]
}
}
Ctrl+Shift+T - New tabCtrl+Shift+W - Close tabCtrl+Tab - Next tab# 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/
# Buka File Explorer dari WSL explorer.exe . # Atau ketik di Windows Explorer: \\wsl$\Ubuntu\home\username\
/home/user/projects/# 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
# WSL2 otomatis expose port ke Windows # Jika di WSL: python -m http.server 8000 # Di Windows akses: http://localhost:8000
# Buat /etc/wsl.conf [network] generateResolvConf = false # Edit /etc/resolv.conf dengan IP statis
| Hari | Topik | Praktik |
|---|---|---|
| 1 | Node.js | Install Node, npm, yarn |
| 2 | Python | pyenv, venv, pip |
| 3 | Go & Rust | Install Go, Rust |
| 4 | VS Code | Remote Development |
| 5 | Git Setup | Git config, SSH keys |
# 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
# Global npm install -g typescript nodemon pm2 # Project lokal npm init -y npm install express
# Install yarn npm install -g yarn # Install pnpm npm install -g pnpm
# Install Python 3.11 sudo apt install -y python3.11 python3.11-venv python3-pip # Set default python3 python3 --version
# Install pyenv curl https://pyenv.run | bash # Install Python tertentu pyenv install 3.11.0 pyenv global 3.11.0
# Buat venv python3 -m venv myenv # Activate source myenv/bin/activate # Install packages pip install flask fastapi django
# 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 curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Activate source $HOME/.cargo/env # Verify rustc --version cargo --version
# Install di VS Code (Remote WSL) # - Go # - Rust Analyzer # - Python # - Node.js
# 1. Install VS Code # https://code.visualstudio.com/ # 2. Install extension "Remote - WSL" # Dari VS Code Extensions (Ctrl+Shift+X)
# 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
# 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 ssh-keygen -t ed25519 -C "[email protected]" # Add ke ssh-agent eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519
# Copy public key cat ~/.ssh/id_ed25519.pub # Atau clip.exe < ~/.ssh/id_ed25519.pub # Paste ke GitHub > Settings > SSH Keys
| Hari | Topik | Praktik |
|---|---|---|
| 1 | Docker | Docker Desktop, Docker di WSL2 |
| 2 | Multiple Distros | Install multiple Linux |
| 3 | Performance | WSL tuning |
| 4 | Backup & Migrate | Export/Import |
| 5 | Troubleshooting | Common issues |
# 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
# 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
# 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
# List available distros wsl --list --online # Install distro lain wsl --install -d Debian wsl --install -d Kali-Linux wsl --install -d Arch-Linux
# List semua WSL wsl --list -v # Set default wsl --set-default Ubuntu # Switch ke distro lain wsl -d Debian wsl -s Kali-Linux
# Tanpa masuk ke shell wsl -d Ubuntu -- python3 --version wsl -d Debian -- apt update
# 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
# Buat .wslconfig di Windows (C:/Users/YourName/) [wsl2] memory=4GB processors=2 swap=2GB localhostForwarding=true
# Non-aktifkan antivirus scanning untuk WSL folder # Tambahkan ke Windows Security > Exclusions \\wsl$\
Apa kepanjangan WSL?
WSL2 menggunakan arsitektur apa?
Command apa untuk install Linux di WSL?