Automated setup script for Ubuntu 24.04 LTS on Windows Subsystem for Linux (WSL2).
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- Prerequisites
- What the Script Does
- Manual Installation Steps
- Files Included
- Post-Installation
- Troubleshooting
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 /norestartRestart your computer after running these commands.
Download and install: WSL2 Linux kernel update package
wsl --set-default-version 2wsl --install -d Ubuntu-24.04
wsl --set-default Ubuntu-24.04The wsl2-setup.sh script automatically:
โ Updates system packages
- Runs
apt-get updateandapt-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
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.shwsl2-setup.sh- Main installation script.bashrc_extra- Custom bash configurationREADME.md- This documentation
After the script completes:
-
Restart WSL2:
wsl --shutdown -
Log out and back in to activate docker group membership:
exit # Then open a new WSL terminal
-
Verify installations:
aws --version docker --version gh --version terraform --version # Installed automatically with tfenv tflint --version
- Strict error handling (
set -euo pipefail) - Clear error messages with color coding
- Graceful handling of already-installed components
- Safe to run multiple times
- Checks if tools are already installed
- Only installs what's missing
- Uses temporary directories with automatic cleanup
- Validates downloads
- Proper file permissions
- Color-coded output:
- ๐ข Green = Info
- ๐ก Yellow = Warning
- ๐ด Red = Error
- ๐ต Blue = Success
If you see Permission denied, add execute permissions:
chmod +x wsl2-setup.shIf 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 terminalAdd to your PATH:
echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bashrc
source ~/.bashrcEdit .bashrc_extra and keep the manage_ssh_keys function commented out (default).
Edit the PS1 variable in .bashrc_extra to customize your prompt.
Modify the CDPATH variable in .bashrc_extra to add your frequently used directories.
Feel free to submit issues or pull requests to improve this script.
This project is open source and available under the MIT License.
- WSL Documentation - Windows Subsystem for Linux
- Ubuntu 24.04 LTS - Official Ubuntu releases
- AWS CLI v2 - AWS Command Line Interface
- AWS Session Manager Plugin - SSM Plugin for secure shell access
- Docker - Container platform installation for Ubuntu
- Docker Compose - Multi-container Docker applications
- GitHub CLI - GitHub command-line tool for Debian/Ubuntu
- Terraform - Infrastructure as Code
- tfenv - Terraform version manager
- tflint - Terraform linter
For issues related to:
- WSL itself: Check Microsoft WSL Issues
- This script: Open an issue in this repository
Made with โค๏ธ for Ubuntu 24.04 LTS on WSL2