Azure CLI: Installing CLI on Mint Linux

Page content

Azure CLI on Linux Mint

Today, I embarked on an exploration of Linux Mint as a potential new desktop environment. Linux Mint stands out as an operating system recognized for its robustness, user-centric design, and unparalleled stability. Its foundation on Ubuntu, which draws from Debian, positions Linux Mint as an exemplary choice for the Linux community. The system’s interface, celebrated for its elegance and simplicity and an extensive software repository, ensures a seamless user experience.

The installation process unfolded smoothly, with most of my essential software integrating without any complications. However, I encountered a notable exception while attempting to install the Azure Command Line Interface (CLI). Typically, the installation procedures for Debian-based systems, as outlined in the Azure CLI documentation, involve identifying the operating system using the lsb_release command. The challenge arises when Linux Mint responds with its specific version information, leading to a discrepancy as the repositories hosting the deployment packages lack support for Mint’s versioning scheme.

Linux Mint utilizes the Advanced Package Tool (APT) for package management on the system. APT is a widely used package management system that automates installing, upgrading, configuring, and removing software. For APT to function effectively, it necessitates the configuration of a deployment repository on the local system. A deployment repository is a storage location from which software packages can be retrieved and installed.

Once a deployment repository is appropriately configured on a Linux Mint system, APT can leverage this repository to download packages and updates for various applications or services. This setup ensures that the software on the system remains up-to-date and secure. The configuration process involves specifying the repository’s details in APT’s configuration files, which APT then uses to fetch software packages according to the user’s commands.

Let’s go over how to install the Azure CLI; this process will work for other deployment packages that use the APT process.

Identifying the version of Mint

Linux Mint’s architecture is derived from Ubuntu, meaning APT packages designed for Ubuntu are typically compatible with Mint, given that the correct corresponding Ubuntu version is identified and used. This compatibility hinges on matching the Linux Mint release with its Ubuntu counterpart based on their code names.

The process for identifying the correct Ubuntu version for a Linux Mint installation involves two main steps:

  1. Identify the Mint Code Name: Utilize the command lsb_release -a in the terminal. This command displays detailed information about your Linux distribution, including the Mint code name. The code name is a crucial identifier that links your Mint version to an Ubuntu version.
craig@mint-01:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Linuxmint
Description:	Linux Mint 21.3
Release:	21.3
Codename:	virginia
craig@ubuntu-1:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.4 LTS
Release:        22.04
Codename:       jammy
  1. Confirm the Corresponding Ubuntu Version: With the Mint code name at hand (e.g., “virginia”), refer to the Mint version table available on the Linux Mint official website Linux Mint Download Page. This table maps each Mint release to its corresponding Ubuntu base. In the example provided, “virginia” is associated with Ubuntu’s “jammy” release.

Azure CLI configuration

The configuration of Azure CLI is thoroughly documented on the Microsoft Learn site under the section Install the Azure CLI on Linux. Among the provided options, the initial method involves using a comprehensive download script to automate the installation process. However, this approach might encounter issues on Linux Mint, as the Microsoft APT repository does not officially support Mint. Consequently, to successfully install Azure CLI on Linux Mint, it’s recommended to follow a manual installation process.

Unfortunately, the manual process outlined on the Microsoft Learn site requires modifications to be fully compatible with Linux Mint. Below are the updated steps, adapted from the official Microsoft documentation, to guide you through the manual installation of Azure CLI on Linux Mint:

  1. Get packages needed for the installation process:
sudo apt update
sudo apt install ca-certificates curl apt-transport-https lsb-release gnupg
  1. Download and install the Microsoft signing key:
sudo mkdir -p /etc/apt/keyrings
curl -sLS https://packages.microsoft.com/keys/microsoft.asc |
    gpg --dearmor |
    sudo tee /etc/apt/keyrings/microsoft.gpg > /dev/null
sudo chmod go+r /etc/apt/keyrings/microsoft.gpg
  1. Add the Azure CLI software repository:

This section is where an update is required. The process uses $(lsb_release -cs) to return the codename; this can be changed to the following by replacing it with the codename string for Mint. In this case, jammy.

# AZ_DIST=$(lsb_release -cs) # Repalce this line
AZ_DIST=jammy
echo "deb [arch=`dpkg --print-architecture` signed-by=/etc/apt/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/azure-cli/ $AZ_DIST main" | 
    sudo tee /etc/apt/sources.list.d/azure-cli.list
  1. Update repository information and install the azure-cli package:
sudo apt update && sudo apt install azure-cli

Updating Azure CLI install process for known versions of Mint

The following section script is what I use to install Azure CLI on my workstations. This script has been updated to find out what version of Mint you are running, then update AZ_REPO with the correct Ubuntu codename. The script section can be adapted to install other software that uses the same method as Azure CLI.

# Get the codename from lsb_release
CODENAME=$(lsb_release -cs)

# Determine the appropriate AZ_REPO value based on the codename
if [ "$CODENAME" = "virginia" ]; then
    AZ_REPO="jammy"
elif [ "$CODENAME" = "victoria" ]; then
    AZ_REPO="jammy"
elif [ "$CODENAME" = "vera" ]; then
    AZ_REPO="jammy"
elif [ "$CODENAME" = "vanessa" ]; then
    AZ_REPO="jammy"
elif [ "$CODENAME" = "una" ]; then
    AZ_REPO="jammy"
elif [ "$CODENAME" = "uma" ]; then
    AZ_REPO="focal"
elif [ "$CODENAME" = "ulyssa" ]; then
    AZ_REPO="focal"
elif [ "$CODENAME" = "ulyana" ]; then
    AZ_REPO="focal"
else
    echo "Unsupported Linux Mint version"
    exit 1
fi

Complete Azure CLI install script

#!/bin/bash

# Set DEBIAN_FRONTEND to noninteractive
export DEBIAN_FRONTEND=noninteractive

# Check if the script is run with root privileges
if [ "$EUID" -ne 0 ]; then
  echo "Please run the script as root or using sudo."
  exit 1
fi

# Updates
sudo apt update 2>&1 | grep -v "WARNING: apt does not have a stable CLI interface"
sudo apt install ca-certificates curl apt-transport-https lsb-release gnupg -y 2>&1 | grep -v "WARNING: apt does not have a stable CLI interface"

# Download and install the Microsoft signing key:
sudo mkdir -p /etc/apt/keyrings
curl -sLS https://packages.microsoft.com/keys/microsoft.asc |
    gpg --dearmor |
    sudo tee /etc/apt/keyrings/microsoft.gpg > /dev/null
sudo chmod go+r /etc/apt/keyrings/microsoft.gpg

# Add Azure CLI software repository
# Get the codename from lsb_release
CODENAME=$(lsb_release -cs)

# Determine the appropriate AZ_REPO value based on the codename
if [ "$CODENAME" = "virginia" ]; then
    AZ_REPO="jammy"
elif [ "$CODENAME" = "victoria" ]; then
    AZ_REPO="jammy"
elif [ "$CODENAME" = "vera" ]; then
    AZ_REPO="jammy"
elif [ "$CODENAME" = "vanessa" ]; then
    AZ_REPO="jammy"
elif [ "$CODENAME" = "una" ]; then
    AZ_REPO="jammy"
elif [ "$CODENAME" = "uma" ]; then
    AZ_REPO="focal"
elif [ "$CODENAME" = "ulyssa" ]; then
    AZ_REPO="focal"
elif [ "$CODENAME" = "ulyana" ]; then
    AZ_REPO="focal"
else
    echo "Unsupported Linux Mint version"
    exit 1
fi
echo "deb [arch=`dpkg --print-architecture` signed-by=/etc/apt/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" |
    sudo tee /etc/apt/sources.list.d/azure-cli.list

# Update repository information and install the azure-cli
sudo apt update 2>&1 | grep -v "WARNING: apt does not have a stable CLI interface"
sudo apt install azure-cli -y 2>&1 | grep -v "WARNING: apt does not have a stable CLI interface"