跳至主要内容

在 RHEL、openSUSE、AlmaLinux 和其他基于 RPM 的发行版上安装 OpenTofu

感谢 Buildkite 中文 赞助 OpenTofu 软件包托管。

您可以按照以下分步说明从我们的 RPM 仓库安装 OpenTofu。

使用安装程序安装

您可以使用 OpenTofu 安装程序脚本运行安装。

代码块
# 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

# Give it execution permissions:
chmod +x install-opentofu.sh

# Please inspect the downloaded script

# Run the installer:
./install-opentofu.sh --install-method rpm

# Remove the installer:
rm -f install-opentofu.sh

分步说明

以下步骤说明了如何设置 OpenTofu RPM 仓库。这些说明应该适用于大多数基于 RPM 的 Linux 系统。

添加 OpenTofu 仓库

通过运行以下命令创建 /etc/yum.repos.d/opentofu.repo 文件

代码块
cat >/etc/yum.repos.d/opentofu.repo <<EOF
[opentofu]
name=opentofu
baseurl=https://packages.opentofu.org/opentofu/tofu/rpm_any/rpm_any/\$basearch
repo_gpgcheck=0
gpgcheck=1
enabled=1
gpgkey=https://get.opentofu.org/opentofu.gpg
https://packages.opentofu.org/opentofu/tofu/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

[opentofu-source]
name=opentofu-source
baseurl=https://packages.opentofu.org/opentofu/tofu/rpm_any/rpm_any/SRPMS
repo_gpgcheck=0
gpgcheck=1
enabled=1
gpgkey=https://get.opentofu.org/opentofu.gpg
https://packages.opentofu.org/opentofu/tofu/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
EOF

安装 OpenTofu

现在,您可以通过运行以下命令安装 OpenTofu:

代码块
sudo yum install -y tofu