# How to Install Ubuntu on WSL 2 in Windows 11

### Overview
  * `WSL 2` is an official tool that allows the use of Linux operating systems on **Windows 10/11** without the need for a virtual machine or dual boot. **Microsoft** offers various Linux operating systems that run natively on **WSL 2** for free in the **Windows Store**. This enables developers to set up a native Linux-based development environment without any cumbersome process or performance degradation.

### Features
  * The `WSL 2` architecture provides the best Linux environment performance within the **Windows** ecosystem because it is based on a lightweight **VM** with a Linux kernel directly produced by Microsoft, in official collaboration with various Linux vendors to provide **WSL distros**.
  * Unlike **Cygwin**, which mimics Linux as closely as possible, it allows the use of binaries exactly the same way in a real Linux shell. (This is especially welcome for developers, as it allows the use of numerous tools that enhance productivity within the powerful Linux ecosystem. Microsoft officially states that **WSL 2** was designed for developers.)
  * File system access between **Windows** and **WSL distros** is possible. In **Windows**, it is accessible via `\wsl$` and in **WSL distros** via the `/mnt` path. (In any case, accessing the opposite file system reduces **I/O** performance. The best performance is shown when accessing the **ext4** file system within the **WSL distro**. Therefore, in my case, both the **IDE** and source code are installed within the **WSL distro**.)

### Prerequisites
  * If `Oracle VirtualBox`, `Vagrant` are currently installed on your **Windows** operating system, remove them.
  * Update the **Windows 10/11** operating system to the latest version. [[Windows 10 Update Link]](https://www.microsoft.com/en-us/software-download/windows11), [[Windows 11 Update Link]](https://www.microsoft.com/en-us/software-download/windows11)
  * Install the `Windows Subsystem for Linux Update`. [[Installation Link]](https://docs.microsoft.com/ko-kr/windows/wsl/install-manual#step-4---download-the-linux-kernel-update-package)

### Installing Ubuntu on WSL
  * `Ubuntu` is the most popular Linux operating system providing a desktop environment. It is officially available on the **Windows Store**, and you can click [here](https://www.microsoft.com/store/productId/9NBLGGH4MSV6) to install the latest **LTS** version as an app. (Upon first launch after installation, it asks for a **username** and **password** to use.) Alternatively, it can also be installed from the console as follows.

```bash
# Install Ubuntu on WSL
$ wsl --install -d ubuntu

# Switch Ubuntu on WSL version to WSL 2
$ wsl --set-version ubuntu 2

# Uninstall Ubuntu on WSL
$ wsl --unregister Ubuntu
```

### Docker Integration
  * Installing `Docker Desktop` on **Windows** allows for the free use of **Docker** in **Ubuntu on WSL**.

```bash
# Install Docker Desktop (Run as Administrator in PowerShell)
$ choco install docker-desktop -y
```

  * To use **Docker** within the installed **Ubuntu** console, the following steps are needed.

```bash
# Run Docker Desktop
→ Settings
→ Resources
→ WSL Integration
→ Enable integration with additional distros: Activate [Ubuntu]
→ Click [Apply & Restart]

# Change the default Terminal in IntelliJ IDEA
Settings
→ Tools
→ Terminal
→ Shell path: Enter [ubuntu run]
```

### Running Ubuntu on WSL Console
  * Running **Ubuntu** on **Windows** is very straightforward. Just execute the `ubuntu` command. If `Windows Terminal` is installed, it automatically recognizes it, so setting it as the default profile is convenient.

```bash
# Run console from home directory
$ ubuntu

# Run console from the current directory
$ ubuntu run

# After console switch, set DNS server
$ sudo nano /etc/wsl.conf
[network]
generateResolvConf = false

$ sudo nano /etc/resolv.conf
nameserver 1.1.1.1
nameserver 8.8.8.8
nameserver 208.67.222.222

$ sudo nano /etc/sysctl.d/99-wsl.conf
net.core.somaxconn=65535
net.ipv4.tcp_max_syn_backlog=65536
fs.inotify.max_user_watches=524288
fs.file-max=2097152
vm.swappiness=10
vm.vfs_cache_pressure=50

# Apply settings
$ sudo sysctl --system

# After console switch, perform the latest update
$ sudo apt-get update
$ sudo apt-get upgrade -y
```

### Running Windows Applications from Ubuntu on WSL Console
  * Conversely, it's also possible to run **Windows** applications from the **WSL 2** console.

```bash
# Run Notepad
$ powershell.exe start notepad foobar.txt

# Register as an alias
$ nano ~/.bash_aliases
alias cmd="powershell.exe start"

# Run using the alias
$ cmd notepad foobar.txt
```

### Increasing WSL Memory Size
  * Increasing the memory size can make the development environment faster and more pleasant.

```bash
# Shutdown WSL
$ wsl --shutdown

# Change memory size to 24GB
$ notepad "$env:USERPROFILE/.wslconfig"
[wsl2]
memory=24GB
networkingMode=mirrored

# Restart WSL
$ Get-Service LxssManager | Restart-Service
```

### (Optional) Installing JetBrainsMono Nerd Font
* `JetBrainsMono Nerd Font` is a font specifically designed and optimized for terminal and coding environments, offering excellent readability and compatibility with various development tools. I highly recommend installing it for an enhanced coding experience. [[Related Link]](https://www.nerdfonts.com/)

```bash
# Download JetBrainsMono Nerd Font from Nerd Fonts
→ https://www.nerdfonts.com/font-downloads
→ Search for "JetBrainsMono"
→ Click [Download]
→ Select all downloaded .ttf files → Right-click → [Install]

# Configure font in Windows Terminal
→ Settings → Profiles → Ubuntu → Appearance
→ Font face: [JetBrainsMono Nerd Font]
→ Font size: [10]
→ Line height: [1.2]
→ Click [Save]
```

### (Optional) Installing Themes to Windows Terminal
* `Snazzy` is a popular terminal color scheme that provides visual elegance and high readability through its dark theme, high contrast, and vibrant colors. You can add this theme to **Windows Terminal** as follows: [[Related Link]](https://github.com/Richienb/windows-terminal-snazzy)
  
```json
Windows Terminal
→ Settings → Open JSON file
    "schemes": 
    [
        {
            "background": "#282828",
            "black": "#282828",
            "blue": "#458588",
            "brightBlack": "#928374",
            "brightBlue": "#83A598",
            "brightCyan": "#8EC07C",
            "brightGreen": "#B8BB26",
            "brightPurple": "#D3869B",
            "brightRed": "#FB4934",
            "brightWhite": "#EBDBB2",
            "brightYellow": "#FABD2F",
            "cursorColor": "#EBDBB2",
            "cyan": "#689D6A",
            "foreground": "#EBDBB2",
            "green": "#98971A",
            "name": "Gruvbox Dark",
            "purple": "#B16286",
            "red": "#CC241D",
            "selectionBackground": "#3C3836",
            "white": "#A89984",
            "yellow": "#D79921"
        },
        {
            "background": "#282A36",
            "black": "#282A36",
            "blue": "#57C7FF",
            "brightBlack": "#686868",
            "brightBlue": "#57C7FF",
            "brightCyan": "#9AEDFE",
            "brightGreen": "#5AF78E",
            "brightPurple": "#FF6AC1",
            "brightRed": "#FF5C57",
            "brightWhite": "#EFF0EB",
            "brightYellow": "#F3F99D",
            "cursorColor": "#97979B",
            "cyan": "#9AEDFE",
            "foreground": "#EFF0EB",
            "green": "#5AF78E",
            "name": "Snazzy",
            "purple": "#FF6AC1",
            "red": "#FF5C57",
            "selectionBackground": "#3E404A",
            "white": "#F1F1F0",
            "yellow": "#F3F99D"
        }
    ],
    
# After adding the scheme, apply it in Windows Terminal
→ Settings → Profiles → Ubuntu → Appearance → Color scheme → [Snazzy]
→ Click [Save]
```
### (Optional) Installing Starship
  * `Starship` is a cross-platform terminal prompt customization tool that provides a modern shell prompt solution with fast performance based on **Rust** and compatibility with various shells. [[Related Link]](https://starship.rs/)

```bash
# Install Starship
$ curl -sS https://starship.rs/install.sh | sh

# Configure Starship to start automatically with bash
$ nano ~/.bashrc
# Add the following line to the end of the file:
eval "$(starship init bash)"

# After editing .bashrc, apply changes
$ source ~/.bashrc

# Apply Gruvbox Rainbow preset
$ starship preset gruvbox-rainbow -o ~/.config/starship.toml
```

### (Optional) Installing eza
  * `eza` is a modern, high-performance file listing tool written in Rust that replaces and extends the traditional ls command. I highly recommend installing it for enhanced file system navigation. [[Related Link]](https://eza.rocks/)

```bash
# Install Rust
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
$ source $HOME/.cargo/env
$ rustup update

# Install eza
$ cargo install eza

# Set up aliases to replace ls command
$ nano ~/.bash_aliases
# eza
alias ls="eza --icons --group-directories-first"
alias ll="eza -lah --icons --git --group-directories-first"
alias lt="eza -lah --icons --git --group-directories-first --tree --level=2"
alias la="eza -a --icons --group-directories-first"
alias l="eza -F --icons --group-directories-first"
```

### (Optional) Installing OpenJDK 21
  * Install `OpenJDK 21` in the development environment as follows. (For convenience, `SDKMAN` was used.)

```bash
# Install SDKMAN
$ curl -s "https://get.sdkman.io" | bash
$ source "$HOME/.sdkman/bin/sdkman-init.sh"

# Install Amazon Corretto 21 and set as the default JDK
$ sdk i java 21.0.8-amzn
$ sdk default java 21.0.8-amzn

$ sdk current java
Using java version 21.0.8-amzn

# Check installed version
$ java --version
openjdk 21.0.8 2025-07-15 LTS
```

### (Optional) Installing Node.js
  * In the **Ubuntu** environment, **Node.js** can be conveniently managed by installing `NVM`. [[Related Link]](https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-20-04)

```bash
# Install NVM
$ cd ~
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
$ source ~/.bashrc

# Print list of installable Node.js versions
$ nvm list-remote

# Install Node.js 20.11.0 LTS
$ nvm install 20.11.0

$ node --version
v20.11.0

$ npm --version
10.2.4
```

### (Optional) Installing AWS CLI v2

```bash
# Install AWS CLI v2
$ cd ~
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
$ unzip awscliv2.zip
$ sudo ./aws/install

$ nano ~/.bash_aliases
alias aws="/usr/local/aws-cli/v2/current/bin/aws"

$ aws --version
aws-cli/2.14.0 Python/3.11.6 Linux/5.15.133.1-microsoft-standard-WSL2 exe/x86_64.ubuntu.22 prompt/off

# Install awslogs
$ sudo apt install python3-pip -y
$ pip install awslogs

# Configure AWS CLI v2
$ aws configure
AWS Access Key ID [None]: 
AWS Secret Access Key [None]: 
Default region name [None]: 
Default output format [None]:
```

### (Optional) Installing Other Useful Utilities
  * Below are examples of useful utilities when using the **Ubuntu** console. [[Related Link]](https://scalereal.com/devops/2020/05/15/10-cli-tools-for-developers-productivity.html)

```bash
# Install zsh, jq, httpie, neofetch, ranger, nmap
$ sudo apt-get install zsh jq httpie neofetch ranger nmap -y

# Install tldr
$ npm install -g tldr

# Install autojump
$ cd ~
$ git clone git://github.com/wting/autojump.git
$ cd autojump
$ ./install.py
$ source /home/jsonobject/.autojump/etc/profile.d/autojump.sh
```

### References
  * [Awesome WSL - Windows Subsystem for Linux](https://github.com/sirredbeard/Awesome-WSL)

### Further Reading
  * [How to install IntelliJ IDEA in Ubuntu on WSL with X410](https://jsonobject.hashnode.dev/how-to-install-intellij-idea-in-ubuntu-on-wsl-with-x410)
