Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Terraform tfenv Tutorial: From Basic to Advanced

What is tfenv?

tfenv is a Terraform version manager that allows you to easily install and manage multiple versions of Terraform on your system. You can switch between different versions of Terraform quickly, which is especially useful when you are working with multiple Terraform projects that require different versions of the tool.


Step 1: Installing tfenv

The first step is to install tfenv on your system. You can install tfenv using Homebrew, Git, or manually.

1.1: Installing with Homebrew (for macOS or Linux)

If you are using macOS or Linux and have Homebrew installed, you can easily install tfenv:

brew install tfenv

1.2: Installing Manually (without Homebrew)

  1. Clone the tfenv repository from GitHub: git clone https://github.com/tfutils/tfenv.git ~/.tfenv
  2. Add the following to your ~/.bashrc (or ~/.zshrc for Zsh users): export PATH="$HOME/.tfenv/bin:$PATH"
  3. Reload your terminal: source ~/.bashrc # or source ~/.zshrc for Zsh users
  4. Verify the installation: tfenv --version

If the installation was successful, you should see the version of tfenv installed.


Step 2: Installing Terraform Versions Using tfenv

With tfenv installed, you can now install specific versions of Terraform.

2.1: Installing the Latest Stable Version

To install the latest stable version of Terraform:

tfenv install latest

This will install the latest stable version of Terraform and set it as the default.

2.2: Installing a Specific Version

To install a specific version of Terraform, use the following command:

tfenv install 1.0.0
Code language: CSS (css)

This installs Terraform 1.0.0. You can replace 1.0.0 with any version you need.

2.3: Installing a Version for a Specific Project

To install a version of Terraform for a specific project, you can create a .terraform-version file in the project directory with the desired version.

For example, if you want to use Terraform 0.15.0 for a project:

  1. Navigate to the project directory: cd ~/projects/my_project
  2. Create a .terraform-version file with the version number: echo "0.15.0" > .terraform-version tfenv will automatically use Terraform 0.15.0 whenever you are in that directory.

Step 3: Switching Between Terraform Versions

With tfenv, switching between installed versions of Terraform is simple.

3.1: Switching to a Specific Version

To switch to a different version that is already installed:

tfenv use 1.1.0
Code language: CSS (css)

This will set Terraform 1.1.0 as the active version.

3.2: Switching to the Version Defined in .terraform-version

If you have a .terraform-version file in your project directory, you can switch to the version specified in that file with:

tfenv use
Code language: PHP (php)

This will automatically switch to the version specified in the .terraform-version file.

3.3: Listing Installed Versions

You can list all installed versions of Terraform with:

tfenv list
Code language: PHP (php)

This shows a list of Terraform versions installed on your system, and it marks the active version.

3.4: Removing a Version

If you want to remove a specific version, use:

tfenv uninstall 1.0.0
Code language: CSS (css)

This removes Terraform version 1.0.0 from your system.


Step 4: Managing Multiple Terraform Versions

4.1: Setting a Global Version

You can set a global version of Terraform that will be used across all projects unless overridden by a .terraform-version file.

To set a global version:

tfenv global 1.1.0
Code language: CSS (css)

This sets Terraform 1.1.0 as the default version for all projects.

4.2: Setting a Local Version (for a specific project)

If you want to use a specific version of Terraform for a particular project, you can set a local version. You can do this by creating a .terraform-version file in the project’s root directory, as shown in Step 2.3.

Alternatively, you can manually specify the version:

tfenv local 0.14.0
Code language: CSS (css)

This will create a .terraform-version file in the current directory, making Terraform 0.14.0 the local version for that project.


Step 5: Use Cases for tfenv

5.1: Working on Multiple Terraform Projects

With tfenv, you can manage multiple versions of Terraform easily. For example:

  • Project A requires Terraform 0.14.0.
  • Project B requires Terraform 1.0.0.
  • Project C requires the latest stable version.

You can use tfenv to easily switch between these versions without any issues.

5.2: Collaborating with Teams

If your team works with different versions of Terraform, tfenv helps ensure everyone is using the same version for a project. By checking in the .terraform-version file, you ensure consistency across your team.


Step 6: Troubleshooting

If you encounter any issues, here are some tips for troubleshooting:

6.1: Verify Installed Versions

If you’re unsure whether a version is installed:

tfenv list
Code language: PHP (php)

6.2: Verify Active Version

To check the current active version of Terraform:

terraform version

This will display the currently active version of Terraform in use.

6.3: Reinstall a Version

If a Terraform version seems to be misbehaving, you can uninstall and then reinstall it:

tfenv uninstall 1.0.0
tfenv install 1.0.0
Code language: CSS (css)

Conclusion

tfenv is an excellent tool for managing multiple versions of Terraform, especially if you’re working with multiple Terraform projects or need to ensure consistent versions across your team. By following the steps in this tutorial, you can easily install, switch between, and manage different versions of Terraform.


Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Team Foundation Server 2015 Installation Guide (SQL Express + Update 3)

Install Team Foundation Server 2015 using the original Microsoft download paths, with clear guidance for online, offline, and ISO-based setup. This revised guide also includes an installation workflow, command example, and practical pitfalls to avoid.

Read More

How to Access a Running Docker Container Shell: docker exec vs docker attach

Need a shell inside a running container that is already in detached mode? This updated guide shows the correct workflow, compares docker exec and docker attach, and explains when SSH does and does not make sense.

Read More

Host Your Own NuGet Feed: Local Source vs NuGet.Server vs NuGetGallery

Learn how to host a private NuGet feed using three practical approaches: a local folder source, NuGet.Server, and NuGetGallery. This revised guide includes setup steps, command examples, and a workflow diagram to help you choose the right model.

Read More

Publish NuGet Packages to NuGet.org: CLI Steps, Workflow, and CI Example

Learn how to publish a NuGet package to NuGet.org using either nuget.exe or the dotnet CLI. This revised guide includes a workflow diagram, command comparison, and a CI-friendly example.

Read More

How to Create NuGet Packages with nuget.exe (Assembly, .nuspec, and .csproj Methods)

Learn three practical ways to build NuGet packages using nuget.exe: from an existing assembly, from a convention-based folder layout, or directly from a Visual Studio project. This guide includes commands, folder conventions, token behavior, and common pitfalls.

Read More

Virtualization in DevOps: Using Vagrant, Docker, and Cloud Platforms Together

This guide explains how VM-based workflows, containers, and cloud platforms complement each other in DevOps. It includes a practical workflow, trade-off table, and command examples for day-to-day use.

Read More
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Jason Mitchell
Jason Mitchell
3 months ago

One area that could be be expanded is how tfenv fits into enterprise IaC workflows and CI/CD automation. The tutorial covers installation and version switching well, but in production environments, simply using tfenv is not enough. Teams should treat .terraform-version as a version-controlled artifact, validate Terraform versions during pull requests, and ensure build agents use the same pinned versions to avoid unexpected plan differences. It would also be useful to discuss migration strategies when upgrading Terraform across multiple repositories, including compatibility testing, provider version constraints, and rollback mechanisms, since managing Terraform versions at scale is often more challenging than switching versions on a developer workstation. 

1
0
Would love your thoughts, please comment.x
()
x