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

1. What You Will Learn


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:

TEXT

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.

⚠️ Note: Cloud servers typically come with a default or random password. You must change the default password immediately after first login, otherwise it's vulnerable to brute-force scanning attacks.

(4) ▶ Example: Install Ubuntu via WSL2

Open PowerShell or CMD as administrator:

POWERSHELL
# Install WSL2 with the default Ubuntu distribution
wsl --install -d Ubuntu

# View installed distributions
wsl -l -v

# Start WSL
wsl

Output:

TEXT
Installing: 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

BASH
# 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:

TEXT
Hit: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

BASH
# 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:

TEXT
VirtualBox 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

BASH
# 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:

TEXT
The 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

BASH
# 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:

TEXT
Linux 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

BASH
# 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 Ubuntu in PowerShell to delete it, or use wsl --shutdown to stop all distributions.


📖 Summary


📝 Exercises

  1. Basic (Difficulty ⭐): Choose one method (WSL2 / VirtualBox / Cloud server) and install a Linux environment on your computer
  2. Intermediate (Difficulty ⭐⭐): After logging in, run lsb_release -a and uname -r to confirm system info, then execute sudo apt update && sudo apt upgrade -y to update the system
  3. Advanced (Difficulty ⭐⭐⭐): Try both WSL2 and VirtualBox, compare their pros and cons (boot speed, file integration, GUI support), and write your own recommendation
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏