Linux: Installing Linux
Learning Linux doesn't require reinstalling your OS or buying a new computer. Whether you use Windows or macOS, there are multiple ways to get a Linux environment.
📋 Prerequisites: You should first complete
- Lesson 1: Introduction to Linux
1. What You Will Learn
- WSL2 installation and configuration
- Installing Ubuntu Server on VirtualBox
- Purchasing a cloud server and connecting via SSH
- Basic configuration after first login
- Choosing the learning environment that suits you best
2. A Story About Choosing an Installation Method
(1) The Pain: Is Installing an OS Really This Complicated?
Alex's Windows computer needed a Linux environment for backend development. His colleague Lisa had used a Mac for a year and never installed Linux. Alex started searching: "best way to run Linux on Windows" — the answers ranged from WSL2 to virtual machines to dual boot to cloud servers, and he was overwhelmed.
(2) Three Options to Choose From
Senior engineer Bob helped him draw a decision tree:
Do you have Windows?
├─ Yes → Do you need a GUI?
│ ├─ No → WSL2 (lightweight)
│ └─ Yes → VirtualBox VM
└─ No (macOS) → Do you need a full environment?
├─ Yes → VirtualBox VM
└─ No → SSH into a cloud server
(3) The Benefit: A Linux Environment in 10 Minutes
Alex chose WSL2, and 10 minutes later he had an Ubuntu terminal on Windows — no virtual machine, no dual boot, fully integrated with the Windows filesystem.
3. Knowledge Points
(1) WSL2 (Windows Subsystem for Linux 2)
WSL2 is Microsoft's Linux kernel compatibility layer for Windows. It runs a real Linux kernel in a lightweight virtual machine but integrates deeply with Windows — you can edit code in C:\ and then run it in the Linux terminal.
System requirements: Windows 10 version 2004+ or Windows 11.
| Feature | WSL1 | WSL2 |
|---|---|---|
| Kernel | Translation layer (incomplete) | Real Linux kernel |
| Performance | Faster filesystem | 100% syscall compatibility |
| Docker | Not supported | Native support |
| Cross-OS file access | Very fast | Slightly slower (recommend keeping projects on the Linux filesystem) |
(2) VirtualBox Virtual Machine
Oracle VirtualBox is a free, open-source virtualization software that can run a complete Linux desktop or server system on Windows/macOS.
Use cases: Need a full Linux GUI, need to simulate network environments, or want to try different distributions.
(3) Cloud Server
Purchasing a cloud server (VPS) is the best way to experience a real production environment. Major providers like DigitalOcean, Alibaba Cloud, and Vultr offer Linux servers starting at $5/month.
Use cases: Learning server management, deploying real applications, need a public IP.
(4) ▶ Example: Install Ubuntu via WSL2
Open PowerShell or CMD as administrator:
# Install WSL2 with the default Ubuntu distribution
wsl --install -d Ubuntu
# View installed distributions
wsl -l -v
# Start WSL
wsl
Output:
TEXTInstalling: Ubuntu Ubuntu installed. NAME STATE VERSION * Ubuntu Running 2
On first launch, you'll be prompted to create a Linux username and password.
ℹ️ Note: Which method to choose depends on your needs — WSL2 is the lightest and integrates with Windows files, VirtualBox is for when you need a full GUI, and a cloud server is closest to a real production environment. Beginners should start with WSL2 and add a cloud server later for hands-on practice.
(5) ▶ Example: WSL2 Basic Configuration
# Update package sources and system
sudo apt update && sudo apt upgrade -y
# Check WSL2 kernel version
uname -r
# Check Ubuntu version
lsb_release -a
# Exit WSL (return to Windows)
exit
Output:
TEXTHit:1 http://archive.ubuntu.com/ubuntu jammy InRelease Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB] ... 5.15.0-91-generic No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.3 LTS Release: 22.04 Codename: jammy
(6) ▶ Example: Install Ubuntu Server on VirtualBox
# 1. Download and install VirtualBox
# 2. Download Ubuntu Server ISO (ubuntu.com/download/server)
# 3. Create new VM: Linux → Ubuntu (64-bit) → 2GB RAM → 20GB disk
# 4. Boot and load ISO → install Ubuntu Server (text-based installer)
# 5. After installation: sudo apt update && sudo apt upgrade
Output:
TEXTVirtualBox VM installed successfully Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-91-generic x86_64)
(7) ▶ Example: First SSH Login to a Cloud Server
# Login with SSH key (recommended)
ssh -i ~/.ssh/mykey.pem ubuntu@your-server-ip
# Or login with password
ssh ubuntu@your-server-ip
# Update the system immediately after first login
sudo apt update && sudo apt upgrade -y
Output:
TEXTThe authenticity of host '203.0.113.10 (203.0.113.10)' can't be established. ED25519 key fingerprint is SHA256:abcd1234efgh5678. Are you sure you want to continue connecting (yes/no)? yes Welcome to Ubuntu 22.04.3 LTS Last login: Tue Jul 8 10:23:45 2026
(8) ▶ Example: Verify Your Environment Is Ready
# Regardless of which method you used, run these after logging in
uname -a
# Sample output: Linux ubuntu 5.15.0-91-generic #101-Ubuntu SMP ...
df -h / # Check root directory disk space
free -h # Check memory
Output:
TEXTLinux ubuntu 5.15.0-91-generic #101-Ubuntu SMP Mon Oct 16 13:30:35 UTC 2023 x86_64 GNU/Linux Filesystem Size Used Avail Use% Mounted on /dev/sda1 40G 12G 26G 32% / total used free shared buff/cache available Mem: 3.8Gi 1.2Gi 1.8Gi 256Mi 812Mi 2.4Gi
(9) ▶ Comprehensive Example: Set Up a WSL2 Development Environment from Scratch
# Step 1: Install WSL2 (run in PowerShell as administrator)
wsl --install -d Ubuntu
# After reboot, open WSL and set your username and password
# Step 2: Update the system
sudo apt update && sudo apt upgrade -y
# Step 3: Install common development tools
sudo apt install -y build-essential curl wget git vim
# Step 4: Verify
echo "=== OS Version ===" && lsb_release -d
echo "=== Kernel ===" && uname -r
echo "=== Disk ===" && df -h /
echo "=== Memory ===" && free -h
# Done! Your Linux environment is ready
Output:
TEXT=== OS Version === Description: Ubuntu 22.04.3 LTS === Kernel === 5.15.0-91-generic === Disk === Filesystem Size Used Avail Use% Mounted on /dev/sda1 40G 12G 26G 32% / === Memory === total used free shared buff/cache available Mem: 3.8Gi 1.2Gi 1.8Gi 256Mi 812Mi 2.4Gi
❓ FAQ
Q: Which is better, WSL2 or dual boot? A: WSL2 is better for most developers — no reboot needed, integrates with Windows files, near-native performance. Dual boot is for those who need a full Linux desktop experience (e.g., GPU computing, Linux desktop development), but switching requires a reboot.
Q: How much does WSL2 performance differ from native Linux? A: CPU and memory performance is nearly 100% native. Disk I/O is slower when accessing the Windows filesystem (
/mnt/c/), so keep project files on the Linux filesystem (~/projects/).
Q: How much does a cloud server cost per month? A: DigitalOcean/Vultr starts at $4-6/month, Alibaba Cloud lightweight server is about ¥34/month. New users typically get $100-$200 in credits.
Q: Where are WSL2 files stored? A: \1
Q: How do I uninstall WSL2? A: Run
wsl --unregister Ubuntuin PowerShell to delete it, or usewsl --shutdownto stop all distributions.
📖 Summary
- WSL2: The recommended method for Windows, ready in 10 minutes, no VM needed
- VirtualBox: The choice when you need a full graphical interface
- Cloud server: Closest to production, ideal for learning server management
- After first login, always run
sudo apt update && sudo apt upgrade -y - Selection criteria: lightweight dev → WSL2, GUI learning → VM, real deployment → cloud server
📝 Exercises
- Basic (Difficulty ⭐): Choose one method (WSL2 / VirtualBox / Cloud server) and install a Linux environment on your computer
- Intermediate (Difficulty ⭐⭐): After logging in, run
lsb_release -aanduname -rto confirm system info, then executesudo apt update && sudo apt upgrade -yto update the system - Advanced (Difficulty ⭐⭐⭐): Try both WSL2 and VirtualBox, compare their pros and cons (boot speed, file integration, GUI support), and write your own recommendation