- 入门
- 安装 OpenTofu
- 独立版 (Linux/MacOS/Windows/BSD)
从 GitHub Releases 安装 OpenTofu
使用安装脚本
- Linux/MacOS/BSD/Unix (POSIX)
- Windows (PowerShell)
# Download the installer script:
curl --proto '=https' --tlsv1.2 -fsSL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh
# Alternatively: wget --secure-protocol=TLSv1_2 --https-only https://get.opentofu.org/install-opentofu.sh -O install-opentofu.sh
# Grant execution permissions:
chmod +x install-opentofu.sh
# Please inspect the downloaded script at this point.
# Run the installer:
./install-opentofu.sh --install-method standalone
# Remove the installer:
rm -f install-opentofu.sh
# Download the installer script:
Invoke-WebRequest -outfile "install-opentofu.ps1" -uri "https://get.opentofu.org/install-opentofu.ps1"
# Please inspect the downloaded script at this point.
# Run the installer:
& .\install-opentofu.ps1 -installMethod standalone
# Remove the installer:
Remove-Item install-opentofu.ps1
注意
如果在运行此脚本时遇到脚本执行策略问题,请在运行安装程序之前运行
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
。将 OpenTofu 作为独立二进制文件使用
您可以将 OpenTofu 作为独立二进制文件运行,无需安装。您可以从 GitHub 发布页面 下载适用于您操作系统的 最新版本,解压缩 zip 文件并开始使用。为了方便更新,我们建议您使用 **适用于您操作系统的非便携式打包版本**。
社区支持的架构
注意
这些是针对 OpenTofu 未正式支持的架构的构建版本。请将有关这些构建版本的问题提交给它们的维护者。
下载 此处 的 ppc64le 最新二进制文件。 联系 ppc64le 维护者 以解决与此二进制文件相关的问题。
验证文件完整性
请从发布版本中下载 tofu_YOURVERSION_SHA256SUMS
文件。此文件包含所有文件的 SHA256 校验和。您可以通过运行以下命令来验证文件的完整性
- Linux (sha256sum)
- MacOS (shasum)
- Windows (PowerShell)
ZIPFILE=tofu_*.zip
CHECKSUM=$(sha256sum "${ZIPFILE}" | cut -f 1 -d ' ')
EXPECTED_CHECKSUM=$(grep "${ZIPFILE}" tofu_*_SHA256SUMS | cut -f 1 -d ' ')
if [ "${CHECKSUM}" = "${EXPECTED_CHECKSUM}" ]; then
echo "OK"
else
echo "MISMATCH"
fi
ZIPFILE=tofu_*.zip
CHECKSUM=$(shasum -a 256 "tofu_*.zip" | cut -f 1 -d ' ')
EXPECTED_CHECKSUM=$(grep "${ZIPFILE}" tofu_*_SHA256SUMS | cut -f 1 -d ' ')
if [ "${CHECKSUM}" = "${EXPECTED_CHECKSUM}" ]; then
echo "OK"
else
echo "MISMATCH"
fi
$zipFile="tofu_YOURVERSION_REPLACEME.zip"
$checksum = $(Get-FileHash -Algorithm SHA256 $zipFile).Hash
$expectedChecksum = $((Get-Content "tofu_YOURVERSION_REPLACEME_SHA256SUMS" | Select-String -Pattern $zipFile) -split '\s+')[0]
if ($realHash -ne $expectedHash) {
Write-Error "Checksum mismatch"
}
使用 Cosign 验证二进制文件
验证完校验和后,您可以使用 Cosign 验证校验和文件本身的完整性。请确保您已安装 Cosign 并下载了发布版本的 tofu_YOURVERSION_SHA256SUMS.pem
和 tofu_YOURVERSION_SHA256SUMS.sig
文件。然后,您可以运行完整性验证
- Linux/MacOS/BSD/UNIX (POSIX)
- Windows (PowerShell)
OPENTOFU_VERSION_MAJORMINOR="Add your OpenTofu major and minor version here"
IDENTITY="https://github.com/opentofu/opentofu/.github/workflows/release.yml@refs/heads/v${OPENTOFU_VERSION_MAJORMINOR}"
# For alpha and beta builds use /main
cosign \
verify-blob \
--certificate-identity "${IDENTITY}" \
--signature "tofu_*.sig" \
--certificate "tofu_*.pem" \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
"tofu_*_SHA256SUMS"
$version = [version]"YOUR_OPENTOFU_VERSION"
$identity = "https://github.com/opentofu/opentofu/.github/workflows/release.yml@refs/heads/v${version.Major}.${version.Minor}"
# For alpha and beta builds use /main
cosign.exe `
verify-blob `
--certificate-identity $identity `
--signature "tofu_YOURVERSION_REPLACEME.sig" `
--certificate "tofu_YOURVERSION_REPLACEME.pem" `
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" `
"tofu_YOURVERSION_REPLACEME_SHA256SUMS"