How to Install and Use OpenTofu on Ubuntu 26.04 and 24.04

Share

To install OpenTofu on Ubuntu 26.04 LTS or 24.04 LTS, use OpenTofu’s signed APT repository or install the official Snap. Both give you the tofu command. OpenTofu reads configuration files and shows what would change before it creates, updates, or removes resources.

Before you begin
  • Use Bash on Ubuntu 26.04 LTS or 24.04 LTS, Desktop or Server. The APT steps below cover amd64 and arm64. Check your Ubuntu version if you’re unsure.
  • You’ll need internet access and sudo to install the CLI. Run the project commands as your regular user.
  • Use a fresh directory for the practice project. Once the CLI is installed, the exercise can run offline.

Install OpenTofu on Ubuntu

Step 1. Choose APT or Snap

Choose one method so your shell finds the version you expect. OpenTofu 1.13.9 was available from both channels in November 2026. These commands install the current package for the channel you choose.

Option A. Install the tofu APT package

Neither Ubuntu release includes OpenTofu in its standard archives. OpenTofu’s repository uses any as its suite on both releases, so the commands are the same on 26.04 and 24.04.

Ubuntu terminal
sudo apt update && sudo apt install -y ca-certificates curl gnupg

Import both signing keys and add the repository. If you already configured OpenTofu with a different .list or .sources file, reconcile that entry first to avoid conflicting Signed-By settings. This block writes the keyrings and repository list at the paths shown.

Ubuntu terminal
(
  set -e
  set -o pipefail

  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 --yes --dearmor \
      -o /etc/apt/keyrings/opentofu-repo.gpg

  sudo chmod a+r /etc/apt/keyrings/opentofu.gpg \
    /etc/apt/keyrings/opentofu-repo.gpg

  sudo tee /etc/apt/sources.list.d/opentofu.list >/dev/null <<'EOF'
deb [signed-by=/etc/apt/keyrings/opentofu.gpg,/etc/apt/keyrings/opentofu-repo.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main
EOF
  sudo chmod a+r /etc/apt/sources.list.d/opentofu.list
)

Both keyrings and the source list need to be readable by APT. After the setup block succeeds, refresh the package index and install tofu.

Ubuntu terminal
sudo apt-get update && sudo apt-get install -y tofu

APT installs the executable at /usr/bin/tofu.

Option B. Install the opentofu Snap

If Snap is available on your system, the OpenTofu Core Team publishes the opentofu package. Classic confinement gives the Snap access to the host like a traditionally installed CLI.

Ubuntu terminal
sudo snap install --classic opentofu

The Snap provides the tofu command at /snap/bin/tofu.

Verify which OpenTofu you are running

Step 2. Check the version and command path

In Bash, type -a lists what your shell can run under that name, including multiple paths. Check it before troubleshooting an unexpected version.

Ubuntu terminal
type -a tofu
tofu version

For the November 2026 package, expect a first line of OpenTofu v1.13.9. If you see two paths, keep the intended install and use its matching removal instructions below for the other one.

To enable tab completion for supported shells, run tofu -install-autocomplete and open a new shell.

Teams that pin a different OpenTofu version per repository can use mise on Ubuntu and check which tofu is active in that project.

Run your first OpenTofu project

Step 3. Create a project and review the first plan

Create a new directory so the exercise has its own state. If mkdir says the directory already exists, pick another name before continuing.

Ubuntu terminal
mkdir "$HOME/opentofu-demo" && cd "$HOME/opentofu-demo"

Save the following as main.tf in that directory. The built-in terraform_data resource stores the input in state. The output block prints the resource’s value after apply.

main.tf
resource "terraform_data" "demo" {
  input = "Hello, Ubuntu"
}

output "message" {
  value = terraform_data.demo.output
}

Initialize the project, format the file, check the configuration, and preview the proposed change. Stop and fix any error before continuing.

Ubuntu terminal
tofu init && tofu fmt && tofu validate && tofu plan

The first plan should show one resource to add. Run apply, review the plan it displays, then type yes if it shows the expected change.

Ubuntu terminal
tofu apply
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Outputs:

message = "Hello, Ubuntu"

Change the input and clean up

Step 4. Update the resource and inspect state

In main.tf, replace Hello, Ubuntu with Hello, OpenTofu. Run a new plan. Look for the old and new input values and 0 to add, 1 to change, 0 to destroy. Review the plan again when apply asks for confirmation.

Ubuntu terminal
tofu plan && tofu apply

The output should now read Hello, OpenTofu. The default local backend writes terraform.tfstate, the record OpenTofu uses to match your configuration to managed resources. When it replaces an existing snapshot, terraform.tfstate.backup holds the prior state.

Keep real state and backup files out of Git. They can contain sensitive values. OpenTofu supports native state and plan encryption at rest. Protect and back up the encryption keys so you can still read the state.

Step 5. Destroy the practice resource

Run this from the practice directory. destroy acts on resources tracked by the selected state and workspace. For a real project, verify both before confirming, since the command can delete live infrastructure.

Ubuntu terminal
tofu destroy

Review the proposed deletion and enter yes to remove the demo resource from state. The configuration and state files can still be present afterward.

Troubleshoot installation

APT reports NO_PUBKEY or cannot read a keyring

Check that both keyring files exist and contain data, the source line names both paths, and the files are readable by _apt. If a key is missing or invalid, rerun the repository setup and look for a curl or gpg error.

Ubuntu terminal
ls -l /etc/apt/keyrings/opentofu.gpg \
  /etc/apt/keyrings/opentofu-repo.gpg \
  /etc/apt/sources.list.d/opentofu.list

If only permissions are wrong, restore read access and retry the index refresh.

Ubuntu terminal
sudo chmod a+r /etc/apt/keyrings/opentofu.gpg \
  /etc/apt/keyrings/opentofu-repo.gpg \
  /etc/apt/sources.list.d/opentofu.list && sudo apt update
The shell cannot find tofu or finds the wrong version

Check type -a tofu and confirm you installed the correct package for your chosen method. For Snap, open a new login session if /snap/bin is missing from PATH. If you use a version manager, check whether its shim appears first.

Update or remove OpenTofu

Update your installed package

For APT, refresh the index and upgrade the installed tofu package.

Ubuntu terminal
sudo apt update && sudo apt install --only-upgrade tofu

Snap normally refreshes automatically. To check for a new revision immediately, run sudo snap refresh opentofu.

Remove the CLI

If you’re decommissioning real infrastructure, verify the project directory, backend and workspace, then review and run tofu destroy before uninstalling. If the infrastructure should stay running, retain its configuration and state.

For APT, purge the CLI and remove the repository file and both dedicated keys created in this guide.

Ubuntu terminal
sudo apt purge tofu &&
sudo rm -f /etc/apt/sources.list.d/opentofu.list \
  /etc/apt/keyrings/opentofu.gpg \
  /etc/apt/keyrings/opentofu-repo.gpg &&
sudo apt update

For Snap, remove the opentofu package.

Ubuntu terminal
sudo snap remove opentofu

Both commands leave .tf and terraform.tfstate files in your separate project directory, such as ~/opentofu-demo, untouched. Keep projects outside package-managed directories such as ~/snap/opentofu, where Snap manages application data.

Frequently asked questions

Why is the APT package called tofu and the Snap called opentofu?

They are package names in different stores. Both install the OpenTofu CLI, which you run with the tofu command.

Can I use OpenTofu without a cloud account?

Yes. A project that uses only terraform_data and local state can run offline after installation. Projects that use remote providers or backends may need network access and credentials.

Does removing OpenTofu delete my infrastructure?

No. Uninstalling the CLI does not act on managed resources or delete configuration and state in your project directory. If you intend to decommission a project, review and destroy its resources before removing OpenTofu.

Helpful Resources

OpenTofu on Reddit Community questions and troubleshooting
OpenTofu documentation Official language and CLI guides
OpenTofu on GitHub Source code, releases and issues
OpenTofu on Snapcraft Official Snap package and channels

Source: OpenTofu’s installation instructions for Debian and Ubuntu.