Skip to content
/ wsl2 Public

Essential scripts for initializing and configuring WSL2 environment on Windows, including a PowerShell script for system preparation and basic environment setup within WSL.

Notifications You must be signed in to change notification settings

solarekm/wsl2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

35 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

WSL2 Ubuntu 24.04 LTS - Basic Configuration

License: MIT Platform Ubuntu Shell GitHub stars

Automated setup script for Ubuntu 24.04 LTS on Windows Subsystem for Linux (WSL2).

๐Ÿš€ Quick Start

Run directly from GitHub without cloning:

bash <(curl -fsSL https://raw.githubusercontent.com/solarekm/wsl2/master/wsl2-setup.sh)

Or download and run locally:

curl -fsSL https://raw.githubusercontent.com/solarekm/wsl2/master/wsl2-setup.sh -o wsl2-setup.sh
chmod +x wsl2-setup.sh
./wsl2-setup.sh

๐Ÿ“‹ Table of Contents

๐Ÿ”ง Prerequisites

1. Enable WSL2

Open PowerShell as Administrator and run:

# Enable WSL feature
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

# Enable Virtual Machine Platform
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Restart your computer after running these commands.

2. Install WSL2 Kernel Update

Download and install: WSL2 Linux kernel update package

3. Set WSL2 as Default

wsl --set-default-version 2

4. Install Ubuntu 24.04

wsl --install -d Ubuntu-24.04
wsl --set-default Ubuntu-24.04

๐ŸŽฏ What the Script Does

The wsl2-setup.sh script automatically:

โœ… Updates system packages

  • Runs apt-get update and apt-get upgrade
  • Installs essential tools: unzip, jq, git, curl, keychain, wslu (WSL utilities)

โœ… Configures custom bash environment (.bashrc_extra)

  • Colored prompt with git branch display
  • Timestamp in prompt
  • AWS CLI completion
  • SSH key management (optional)

โœ… Installs AWS CLI v2

  • Downloads and installs latest AWS CLI
  • Skips if already installed

โœ… Installs AWS Session Manager Plugin

  • Enables SSM connectivity to AWS instances
  • Skips if already installed

โœ… Installs Docker

  • Adds Docker official repository
  • Installs Docker Engine, CLI, containerd
  • Installs Docker Compose and Buildx plugins
  • Configures Docker to start on boot
  • Adds user to docker group
  • Skips if already installed

โœ… Installs GitHub CLI (gh)

  • Command-line tool for GitHub repositories
  • Manage PRs, issues, and GitHub Actions workflows
  • Skips if already installed

โœ… Installs Terraform Version Manager (tfenv)

  • Clones tfenv for managing multiple Terraform versions
  • Automatically installs latest stable Terraform 1.x
  • Configures PATH for immediate availability
  • Skips if already installed

โœ… Installs tflint

  • Terraform linter for static code analysis
  • Helps maintain best practices and catch errors
  • Skips if already installed

๐Ÿ“ฆ Manual Installation Steps

If you prefer to clone the repository:

# Clone the repository
git clone https://github.com/solarekm/wsl2.git
cd wsl2

# Make script executable
chmod +x wsl2-setup.sh

# Run the script
./wsl2-setup.sh

๐Ÿ“ Files Included

  • wsl2-setup.sh - Main installation script
  • .bashrc_extra - Custom bash configuration
  • README.md - This documentation

๐Ÿ”„ Post-Installation

After the script completes:

  1. Restart WSL2:

    wsl --shutdown
  2. Log out and back in to activate docker group membership:

    exit
    # Then open a new WSL terminal
  3. Verify installations:

    aws --version
    docker --version
    gh --version
    terraform --version  # Installed automatically with tfenv
    tflint --version

๐Ÿ” Script Features

Error Handling

  • Strict error handling (set -euo pipefail)
  • Clear error messages with color coding
  • Graceful handling of already-installed components

Idempotency

  • Safe to run multiple times
  • Checks if tools are already installed
  • Only installs what's missing

Security

  • Uses temporary directories with automatic cleanup
  • Validates downloads
  • Proper file permissions

Logging

  • Color-coded output:
    • ๐ŸŸข Green = Info
    • ๐ŸŸก Yellow = Warning
    • ๐Ÿ”ด Red = Error
    • ๐Ÿ”ต Blue = Success

๐Ÿ› Troubleshooting

Permission Denied

If you see Permission denied, add execute permissions:

chmod +x wsl2-setup.sh

Docker Permission Issues

If Docker commands fail with permission errors:

# Check if you're in the docker group
groups

# If not, restart WSL (no admin needed)
wsl --shutdown
# Then reopen WSL terminal

AWS CLI Not Found

Add to your PATH:

echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

๐Ÿ“ Customization

Disable SSH Key Management

Edit .bashrc_extra and keep the manage_ssh_keys function commented out (default).

Change Prompt

Edit the PS1 variable in .bashrc_extra to customize your prompt.

Custom CDPATH

Modify the CDPATH variable in .bashrc_extra to add your frequently used directories.

๐Ÿค Contributing

Feel free to submit issues or pull requests to improve this script.

๐Ÿ“„ License

This project is open source and available under the MIT License.

๐Ÿ”— Useful Links

Official Documentation

Installed Tools

๐Ÿ“ฎ Support

For issues related to:


Made with โค๏ธ for Ubuntu 24.04 LTS on WSL2

About

Essential scripts for initializing and configuring WSL2 environment on Windows, including a PowerShell script for system preparation and basic environment setup within WSL.

Topics

Resources

Stars

Watchers

Forks

Languages