September 20, 2023

Get started with OpenTofu by installing from source

By
Ryan Fee

Interested in testing out OpenTofu before the initial release? It’s easy to do by installing from source, just follow the instructions below:

First, make sure you have GO installed, specifically the version listed here.

Clone the OpenTofu repository using the command below:

git clone https://github.com/opentofu/opentofu.git

Ensure you are in the opentofu directory and now compile the package as well as the dependencies:

go build -ldflags "-w -s -X 'github.com/opentofu/opentofu/version.dev=no'" -o bin/ .

Change directories to bin where the binary was placed. That’s it! You can now test using the tofu command. 


tofu

Usage: tofu [global options] <subcommand> [args]

The available commands for execution are listed below.
The primary workflow commands are given first, followed by
less common or more advanced commands.

Main commands:
  init          Prepare your working directory for other commands
  validate      Check whether the configuration is valid
  plan          Show changes required by the current configuration
  apply         Create or update infrastructure
  destroy       Destroy previously-created infrastructure

All other commands:
  console       Try OpenTofu expressions at an interactive command prompt
  fmt           Reformat your configuration in the standard style
  force-unlock  Release a stuck lock on the current workspace
  get           Install or upgrade remote OpenTofu modules
  graph         Generate a Graphviz graph of the steps in an operation
  import        Associate existing infrastructure with a OpenTofu resource
  login         Obtain and save credentials for a remote host
  logout        Remove locally-stored credentials for a remote host
  metadata      Metadata related commands
  output        Show output values from your root module
  providers     Show the providers required for this configuration
  refresh       Update the state to match remote systems
  show          Show the current state or a saved plan
  state         Advanced state management
  taint         Mark a resource instance as not fully functional
  test          Execute integration tests for OpenTofu modules
  untaint       Remove the 'tainted' state from a resource instance
  version       Show the current OpenTofu version
  workspace     Workspace management

Global options (use these before the subcommand, if any):
  -chdir=DIR    Switch to a different working directory before executing the
                given subcommand.
  -help         Show this help output, or the help for a specified subcommand.
  -version      An alias for the "version" subcommand.

Other Install Options

To install with experimental features, the following command can be used:

go build -ldflags "-w -s -X 'main.experimentsAllowed=yes'" -o bin/ .

Have questions or issues? Feel free to open an issue or start a discussion in the OpenTofu repository.

Start using the Terraform platform of the future.

A screenshot of the modules page in the Scalr Platform