May 22nd, 2023 — TUTORIALS

Installing the Azure CLI on the Linux Subsystem in Windows 11

I recently obtained a Windows 11 laptop and immediately gravitated towards the powerful Windows Subsystem for Linux available through the command prompt. I have always preferred the Linux CLI and the open source tools available there over the Windows PowerShell ecosystem, and access to a Linux CLI within Windows is a huge win! We can configure our Azure development environment with ease via the Ubuntu CLI.

To access the Linux CLI in Windows 11, you may first need to install it. Thankfully, they’ve made this easy as well! Open a command prompt as an administrator and enter this command:

wsl --install

When the subsystem finishes installing, you will be asked to restart your computer. At some point in the process, you will be asked to choose a password for your Linux machine. Don’t forget to save that password for reference! I prefer 1Password as a system for keeping my credentials safe.

Customize Your Linux Distribution (If You Must)

The default Linux OS is Ubuntu, which I kept. If you have a preference for another Linux distribution, you can specify it when installing WSL. To see the available distributions, run the command below in Windows Powershell.

PS C:\Users\linuxguy> wsl -l -o
The following is a list of valid distributions that can be installed.
Install using 'wsl.exe --install <Distro>'.

NAME                                   FRIENDLY NAME
Ubuntu                                 Ubuntu
Debian                                 Debian GNU/Linux
kali-linux                             Kali Linux Rolling
Ubuntu-18.04                           Ubuntu 18.04 LTS
Ubuntu-20.04                           Ubuntu 20.04 LTS
Ubuntu-22.04                           Ubuntu 22.04 LTS
OracleLinux_7_9                        Oracle Linux 7.9
OracleLinux_8_7                        Oracle Linux 8.7
OracleLinux_9_1                        Oracle Linux 9.1
SUSE-Linux-Enterprise-Server-15-SP4    SUSE Linux Enterprise Server 15 SP4
openSUSE-Leap-15.4                     openSUSE Leap 15.4
openSUSE-Tumbleweed                    openSUSE Tumbleweed

Please customize at your own risk. This tutorial assumes you are using the default Ubuntu distribution.

Installing Azure CLI

Let’s get down to business! Next, select your WSL CLI.

Select the Ubuntu CLI in the Windows Subsystem for Linux

The Microsoft team has provided a simple single command to install the CLI. If you prefer a multi-step process to install the CLI, that option is also available.

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

When that process is finished, type az --version in your Ubuntu command prompt, and you will see something like this:

azure-cli                         2.48.1

core                              2.48.1
telemetry                          1.0.8

Dependencies:
msal                              1.20.0
azure-mgmt-resource               22.0.0

Python location '/opt/az/bin/python3'
Extensions directory '/home/linuxguy/.azure/cliextensions'

Python (Linux) 3.10.10 (main, Apr 25 2023, 04:23:10) [GCC 11.3.0]

Legal docs and information: aka.ms/AzureCliLegal


Your CLI is up-to-date.

Log In to Azure Cloud

To interact with your Azure resources, you need to authenticate the CLI client. In your Ubuntu CLI, type the command, az login. When you do, your browser will open and prompt you to authenticate. On success, you will be able to return to your CLI by closing the browser window.

When your az login command has completed, you will see a list of the resources available to you. To discover available commands, you can use az find function where function is a word for which you hope to discover a command. See the output for the find command below.

Finding examples...

Here are the most common ways to use [function]: 

Show function details. (autogenerated)
az functionapp function show --function-name MyFunctionName --name MyFunctionAppName --resource-group MyResourceGroup

Delete a function.
az functionapp function delete --resource-group MyResourceGroup --name MyFunctionAppName --function-name MyFunctionName

Hopefully, this tutorial will help you get started quickly. Please don’t hesitate to reach out if you have any questions.

Harvey Ramer
Harvey Ramer
Harvey has been writing code for twenty years. He builds web applications with React, Node.js, and MongoDB and deploys them to the cloud with CI/CD pipelines. He talks and writes about the Christian worldview, technology, startups, and how differences can become a collaborative asset.