Installing Azure CLI Using CURL

Overview

In preparation for some upcoming work using the Azure platform I took the Pluralsight course Developing with Node.js on Microsoft Azure - Getting Started by Scott Allen. In the course the Azure portal is used for many of the configuration and administration tasks but Scott also demonstrates the use of the Azure Command Line Interface. I installed the Azure CLI but had a lot of trouble on the way.

The AZ not found problem

The first step is to Install Bash - Ubuntu on Windows which is fairly easy to accomplish. Next I used the instructions at Install Azure CLI 2.0 for the CLI install. I ran all the scripts in the section ‘Windows -> Bash on Ubuntu’ under the Windows section:

1
2
3
4
5
6
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ wheezy main" | \
sudo tee /etc/apt/sources.list.d/azure-cli.list
sudo apt-key adv --keyserver packages.microsoft.com --recv-keys 417A0893
sudo apt-get install apt-transport-https
sudo apt-get update && sudo apt-get install azure-cli

There is a warning to run the last command twice, which I did. But when I tried to run “az –version” I would get a message the az command is unknown. I did a lot of searches and tried a lot of fixes from Stack Overflow and other sources to no avail.

The page Failure during installing the azure-cli 2.0 in Bash on Ubuntu on Windows #1075 instructs you to run the following commands before installing the CLI on Bash for Windows.

1
2
3
sudo apt-get update
sudo apt-get install -y libssl-dev libffi-dev
sudo apt-get install -y python-dev

Not being sure about the last command, I also ran:

1
sudo apt-get install -y python3-dev

But trying the original install scripts again did not work.

Piping CURL into Bash - A victim-less crime

Then somewhere, and I can’t pin down where, I saw this command for the install:

1
curl -L https://aka.ms/InstallAzureCli | bash

There is an entry under ‘Errors with curl redirection’ on the page Install Troubleshooting that gives a workaround if the command does not work. Running the curl command did the trick. It was obvious that this was different because there were now user prompts not present in the original install I tried:

1
2
3
4
5
6
7
===> In what directory would you like to place the install? (leave blank to use '/home/fredwebs/lib/azure-cli'):
===> In what directory would you like to place the 'az' executable? (leave blank to use '/home/fredwebs/bin'):
===> Modify profile to update your $PATH and enable shell/tab completion now? (Y/n): y
===> Enter a path to an rc file to update (leave blank to use '/home/fredwebs/.bashrc'):

In trying to find the source of this command I pulled up a few pages of strong opinions about using CURL and Bash with a pipe. One of these had the title about the victim-less crime. As Ford Prefect told Arthur Dent once, “Don’t knock it, it worked.”