Linux Mint に azure-cli をインストールする

例によって新しい仕事に関連して azure-cli をインスールする必要があったのでそのメモ。

Linux Mint の場合 lsb_release コマンドでは Ubuntu コードネームを返さないといいつものトラップがあるのでそれを回避す必要があるよという話。

手順

基本、Microsoft の公式の案内通りですが、Ubuntu のコードネームを手動で設定してやる必要があります。

Linux Mint 21.3 の場合は、 jammy にする必要があります。 このコードネームは /etc/os-release 見るのが一番手っ取り早いと思う。

$ cat  /etc/os-release 
NAME="Linux Mint"
VERSION="21.3 (Virginia)"
ID=linuxmint
ID_LIKE="ubuntu debian"
PRETTY_NAME="Linux Mint 21.3"
VERSION_ID="21.3"
HOME_URL="https://www.linuxmint.com/"
SUPPORT_URL="https://forums.linuxmint.com/"
BUG_REPORT_URL="http://linuxmint-troubleshooting-guide.readthedocs.io/en/latest/"
PRIVACY_POLICY_URL="https://www.linuxmint.com/"
VERSION_CODENAME=virginia
UBUNTU_CODENAME=jammy

こんな感じで jammy とわかる

$ sudo apt update
$ sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
// 上の行はたいてい入っているはずだからいらない

// 鍵をダウンロードする
$ 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

//$ AZ_DIST=$(lsb_release -cs) の代わりに直接指定する
$  AZ_DIST=jammy
echo "Types: deb
URIs: https://packages.microsoft.com/repos/azure-cli/
Suites: ${AZ_DIST}
Components: main
Architectures: $(dpkg --print-architecture)
Signed-by: /etc/apt/keyrings/microsoft.gpg" | sudo tee /etc/apt/sources.list.d/azure-cli.sources

$ sudo apt update
$ sudo apt install azure-cli

$ az -v
azure-cli                         2.61.0

core                              2.61.0
telemetry                          1.1.0

Dependencies:
msal                              1.28.0
azure-mgmt-resource               23.1.1

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

Python (Linux) 3.11.8 (main, May 16 2024, 03:47:28) [GCC 11.4.0]

Legal docs and information: aka.ms/AzureCliLegal


Your CLI is up-to-date.

こんな感じで実行できる。

こういうケースでアップストリームのコードネームを取れるコマンドってきっとありそうだが、知らないので少し気にして調べてみよう。

今度のプロジェクトでは C#が必要らしいが、Linux の Mono でいいんか?んー、よくわかりません。

参考

Azure CLI を Linux にインストールする | Microsoft Learn