安装 Bicep(预览版)Install Bicep (Preview)

了解如何设置 Bicep 开发和部署环境。Learn how to set up Bicep development and deployment environments.

开发环境Development environment

要获得最佳 Bicep 创作体验,需要两个组件:To get the best Bicep authoring experience, you need two components:

  • 用于 Visual Studio Code 的 Bicep 扩展。Bicep extension for Visual Studio Code. 若要创建 Bicep 文件,需要一个很好的 Bicep 编辑器。To create Bicep files, you need a good Bicep editor. 建议使用装有 Bicep 扩展Visual Studio CodeWe recommend Visual Studio Code with the Bicep extension. 这些工具提供语言支持和资源自动完成功能。These tools provide language support and resource autocompletion. 它们可帮助创建和验证 Bicep 文件。They help create and validate Bicep files. 有关使用 Visual Studio Code 和 Bicep 扩展的详细信息,请参阅快速入门:使用 Visual Studio Code 创建 Bicep 文件For more information about using Visual Studio Code and the Bicep extension, see Quickstart: Create Bicep files with Visual Studio Code.
  • Bicep CLI。Bicep CLI. 使用 Bicep CLI 将 Bicep 文件编译到 ARM JSON 模板,并将 ARM JSON 模板反编译为 Bicep 文件。Use Bicep CLI to compile Bicep files to ARM JSON templates, and decompile ARM JSON templates to Bicep files. 有关安装说明,请参阅安装 Bicep CLIFor the installation instructions, see Install Bicep CLI.

部署环境Deployment environment

若要部署本地 Bicep 文件,需要两个组件:To deploy local Bicep files, you need two components:

安装组件后,可以使用以下内容部署 Bicep 文件:After the components are installed, you can deploy a Bicep file with:

New-AzResourceGroupDeployment `
  -Name ExampleDeployment `
  -ResourceGroupName ExampleGroup `
  -TemplateFile <path-to-template-or-bicep> `
  -storageAccountType Standard_GRS

安装 Bicep CLIInstall Bicep CLI

与 Azure CLI 一起使用Use with Azure CLI

安装了 Azure CLI 2.20.0 或更高版本后,当执行依赖于 Bicep CLI 的命令时,会自动安装 Bicep CLI。With Azure CLI version 2.20.0 or later installed, the Bicep CLI is automatically installed when a command that depends on it is executed. 例如:For example:

az deployment group create --template-file azuredeploy.bicep --resource-group myResourceGroup

or

az bicep ...

还可以使用内置命令手动安装 CLI:You can also manually install the CLI using the built-in commands:

az bicep install

升级到最新版本:To upgrade to the latest version:

az bicep upgrade

安装特定版本:To install a specific version:

az bicep install --version v0.3.255

重要

Azure CLI 安装独立版本的 Bicep CLI,该版本与你可能拥有的所有其他 Bicep 安装不冲突,并且 Azure CLI 不会将 Bicep CLI 添加到你的路径。Azure CLI installs a separate version of the Bicep CLI that is not in conflict with any other Bicep installs you may have, and Azure CLI does not add Bicep CLI to your PATH. 若要使用 Bicep CLI 编译/反向编译 Bicep 文件,或者若要使用 Azure PowerShell 部署 Bicep 文件,请参阅手动安装与 Azure PowerShell 一起使用To use Bicep CLI to compile/decompile Bicep files, or to use Azure PowerShell to deploy Bicep files, see Install manually or Use with Azure Powershell.

列出所有可用版本的 Bicep CLI:To list all available versions of Bicep CLI:

az bicep list-versions

显示已安装的版本:To show the installed versions:

az bicep version

与 Azure PowerShell 一起使用Use with Azure PowerShell

Azure PowerShell 尚不能安装 Bicep CLI。Azure PowerShell does not have the capability to install the Bicep CLI yet. Azure PowerShell(v5.6.0 或更高版本)预计已安装 Bicep CLI 并在路径中提供。Azure PowerShell (v5.6.0 or later) expects that the Bicep CLI is already installed and available on the PATH. 遵循手动安装方法之一。Follow one of the manual install methods.

若要部署 Bicep 文件,需要 Bicep CLI 0.3.1 或更高版本。To deploy Bicep files, Bicep CLI version 0.3.1 or later is required. 检查 Bicep CLI 版本:To check the Bicep CLI version:

bicep --version

重要

Azure CLI 安装其自包含 Bicep CLI 版本。Azure CLI installs its own self-contained version of Bicep CLI. 即使为 Azure CLI 安装了所需版本,Azure PowerShell 部署也会失败。Azure PowerShell deployment fails even if you have the required versions installed for Azure CLI.

安装 Bicep CLI 后,只要部署 cmdlet 需要,就会调用 Bicep CLI。Once the Bicep CLI is installed, Bicep CLI is called whenever it is required for a deployment cmdlet. 例如:For example:

New-AzResourceGroupDeployment -ResourceGroupName myResourceGroup -TemplateFile azuredeploy.bicep

手动安装Install manually

以下方法安装 Bicep CLI 并将其添加到你的路径。The following methods install the Bicep CLI and add it to your PATH.

LinuxLinux

# Fetch the latest Bicep CLI binary
curl -Lo bicep https://github.com/Azure/bicep/releases/latest/download/bicep-linux-x64
# Mark it as executable
chmod +x ./bicep
# Add bicep to your PATH (requires admin)
sudo mv ./bicep /usr/local/bin/bicep
# Verify you can now access the 'bicep' command
bicep --help
# Done!

macOSmacOS

通过 homebrewvia homebrew
# Add the tap for bicep
brew tap azure/bicep

# Install the tool
brew install bicep
macOS 手动安装macOS manual install
# Fetch the latest Bicep CLI binary
curl -Lo bicep https://github.com/Azure/bicep/releases/latest/download/bicep-osx-x64
# Mark it as executable
chmod +x ./bicep
# Add Gatekeeper exception (requires admin)
sudo spctl --add ./bicep
# Add bicep to your PATH (requires admin)
sudo mv ./bicep /usr/local/bin/bicep
# Verify you can now access the 'bicep' command
bicep --help
# Done!

WindowsWindows

Windows InstallerWindows Installer

下载并运行最新的 Windows 安装程序Download and run the latest Windows installer. 安装程序不需要管理权限。The installer does not require administrative privileges. 安装完成后,会将 Bicep CLI 添加到用户路径。After the installation, Bicep CLI is added to your user PATH. 关闭并重新打开任何打开的命令行界面窗口,以使路径更改生效。Close and reopen any opened command shell windows for the PATH change to take effect.

ChocolateyChocolatey
choco install bicep
WingetWinget
winget install -e --id Microsoft.Bicep
通过 PowerShell 手动Manual with PowerShell
# Create the install folder
$installPath = "$env:USERPROFILE\.bicep"
$installDir = New-Item -ItemType Directory -Path $installPath -Force
$installDir.Attributes += 'Hidden'
# Fetch the latest Bicep CLI binary
(New-Object Net.WebClient).DownloadFile("https://github.com/Azure/bicep/releases/latest/download/bicep-win-x64.exe", "$installPath\bicep.exe")
# Add bicep to your PATH
$currentPath = (Get-Item -path "HKCU:\Environment" ).GetValue('Path', '', 'DoNotExpandEnvironmentNames')
if (-not $currentPath.Contains("%USERPROFILE%\.bicep")) { setx PATH ($currentPath + ";%USERPROFILE%\.bicep") }
if (-not $env:path.Contains($installPath)) { $env:path += ";$installPath" }
# Verify you can now access the 'bicep' command.
bicep --help
# Done!

安装每日版Install the nightly builds

如果要在发布之前尝试最新的预发行版 Bicep,请参阅安装每日版If you'd like to try the latest pre-release bits of Bicep before they are released, see Install nightly builds.

警告

这些预发布版本更有可能存在已知或未知 bug。These pre-release builds are much more likely to have known or unknown bugs.

后续步骤Next steps

开始浏览 Bicep 快速入门Get started with the Bicep quickstart.