Azure Tip: Running the Azure CLI using Bash on Ubuntu, in Windows 10

I recently got a question about how to use the Bash CLI instead of the Windows-based CMD experience, but remaining in Windows and not have to set up virtual machines or other computers.

The Azure team is doing an awesome job in expanding the functionality in the Azure CLI, and this goes cross-platform. It's pretty straight forward, and since I was asked I'll outline the steps here for future reference.

1. Enable the Windows Subsystem for Linux on Windows 10

The first thing we need to do on our Windows 10 box is to enable the Linux Subsystem, which is done from the Windows Fetures dialogue:

Once enabled, ensure you reboot your machine. (You know - Windows, rebooting and all that jazz...)

2. Install the Ubuntu app from the Microsoft Store

Once the feature is enabled, we'll find bash.exe on the Start Menu. Launching it will give you further instructions, saying you'll need to select a distribution to run on your subsystem:

Head on over to the Microsoft Store, search for Bash for example, and click the App called Ubuntu.

Click Get:

Et voila! It's installing:

Once it is done, you can install the Azure CLI directly into this distro. Microsoft have detailed instructions about it here.

Just run these commands to set it up:

AZ_REPO=$(lsb_release -cs)
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | \
     sudo tee /etc/apt/sources.list.d/azure-cli.list

then:

sudo apt-key adv --keyserver packages.microsoft.com --recv-keys 52E16F86FEE04B979B07E28DB02C46DF417A0893
sudo apt-get install apt-transport-https
sudo apt-get update && sudo apt-get install azure-cli

And we're done:

Run Bash and install Azure CLI

With those few simple steps, we're prepared to take on the Azure CLI using the Ubuntu dist on our Windows 10 box using Bash. Awkward, strange, awesome, ingenious and fun. Right?

As you always do, run your login commands to the Azure CLI:

az login

If things were setup correctly, you'll see a positive result:

Now you can use the Azure CLI as you normally would on any other system as well, but running in Bash:

Resources

Microsoft Docs: Install Azure CLI on Ubuntu or Debian

A complex concept made extremely simple in Windows 10 - hope it'll help someone to get it running quickly.