メインコンテンツへスキップ

.deb ベースの Linux (Debian, Ubuntu など) に OpenTofu をインストールする

ご支援ありがとうございます Buildkite OpenTofu パッケージホスティングのスポンサーである。

以下のステップバイステップの手順に従って、Debian リポジトリから 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 deb

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

ステップバイステップの手順

以下のステップでは、OpenTofu Debian リポジトリを設定する方法を説明します。これらの手順は、ほとんどの Debian ベースの Linux システムで動作するはずです。

ツールのインストール

リポジトリを追加するには、いくつかのツールをインストールする必要があります。ほとんどの Debian ベースのオペレーティングシステムでは、これらのツールはすでにインストールされています。

コードブロック
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg

OpenTofu リポジトリの設定

まず、OpenTofu GPG キーのコピーがあることを確認する必要があります。これにより、パッケージが公式パイプラインを使用して作成され、改ざんされていないことが検証されます。

コードブロック
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://get.opentofu.org/opentofu.gpg | sudo tee /etc/apt/keyrings/opentofu.gpg >/dev/null
curl -fsSL https://packages.opentofu.org/opentofu/tofu/gpgkey | sudo gpg --no-tty --batch --dearmor -o /etc/apt/keyrings/opentofu-repo.gpg >/dev/null
sudo chmod a+r /etc/apt/keyrings/opentofu.gpg /etc/apt/keyrings/opentofu-repo.gpg

次に、OpenTofu ソースリストを作成する必要があります。

コードブロック
echo \
"deb [signed-by=/etc/apt/keyrings/opentofu.gpg,/etc/apt/keyrings/opentofu-repo.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main
deb-src [signed-by=/etc/apt/keyrings/opentofu.gpg,/etc/apt/keyrings/opentofu-repo.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main" | \
sudo tee /etc/apt/sources.list.d/opentofu.list > /dev/null
sudo chmod a+r /etc/apt/sources.list.d/opentofu.list

OpenTofu のインストール

最後に、OpenTofu をインストールできます

コードブロック
sudo apt-get update
sudo apt-get install -y tofu