DEV Community

karoon sillapapan
karoon sillapapan

Posted on

Installing AWS CLI v2 on WSL (Ubuntu)

Installing AWS CLI v2 on WSL (Ubuntu)

This guide walks you through installing the AWS Command Line Interface (CLI) version 2 on Windows Subsystem for Linux (WSL) with Ubuntu.

Prerequisites

  • WSL with Ubuntu installed
  • Internet connection
  • Basic terminal knowledge

Installation Steps

There are two main methods to install AWS CLI v2 on WSL Ubuntu:

Method 1: Using the Official Installer (Recommended)

This is the recommended method as it installs the latest AWS CLI v2 directly from Amazon.

# 1. Update your Ubuntu packages
sudo apt update
sudo apt upgrade -y

# 2. Install unzip if you don't have it already
sudo apt install -y unzip curl

# 3. Download the AWS CLI v2 installation package
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"

# 4. Unzip the installer
unzip awscliv2.zip

# 5. Run the install program
sudo ./aws/install

# 6. Verify the installation
aws --version
Enter fullscreen mode Exit fullscreen mode

Method 2: Using Python pip (Alternative for AWS CLI v1)

This method installs AWS CLI v1, which is an older version but may be sufficient for basic needs.

# 1. Install Python and pip if not already installed
sudo apt update
sudo apt install -y python3 python3-pip

# 2. Install AWS CLI using pip
pip3 install awscli --upgrade --user

# 3. Add the installation directory to your PATH
echo 'export PATH=$PATH:~/.local/bin' >> ~/.bashrc
source ~/.bashrc

# 4. Verify the installation
aws --version
Enter fullscreen mode Exit fullscreen mode

Configuring AWS CLI

After installation, you need to configure AWS CLI with your credentials:

# Run the AWS configure command
aws configure
Enter fullscreen mode Exit fullscreen mode

You'll be prompted to enter:

  • AWS Access Key ID
  • AWS Secret Access Key
  • Default region name (e.g., us-west-2, eu-west-1)
  • Default output format (json, text, or yaml)

Updating AWS CLI

To update an existing AWS CLI v2 installation:

# 1. Download the latest version
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"

# 2. Unzip the installer
unzip -u awscliv2.zip

# 3. Update the existing installation
sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
Enter fullscreen mode Exit fullscreen mode

Troubleshooting

  1. If aws --version returns "command not found":

    • Restart your terminal or run source ~/.bashrc
    • Verify the installation path is in your PATH variable
  2. If you encounter permission errors:

    • Make sure you're using sudo when required
    • Check file permissions in the installation directory
  3. For "Fatal error condition" issues:

    • This can happen with certain WSL configurations
    • Try using Method 2 (pip installation) instead

Additional Resources

Top comments (0)