Skip to main content

Command Palette

Search for a command to run...

How to install "tfenv" Terraform version manager on Ubuntu OS

Published
2 min read
How to install "tfenv" Terraform version manager on Ubuntu OS
M

Hey, I'm a postgraduate in Cyber Security with practical experience in Software Engineering and DevOps Operations. The top player on TryHackMe platform, multilingual speaker (Kazakh, Russian, English, Spanish, and Turkish), curios person, bookworm, geek, sports lover, and just a good guy to speak with!

Overview:

tfenv - is an open-source Terraform version manager tool. With this tool, you can easily install any required version of Terraform on your system and switch to other versions if needed.

Tested:
Ubuntu 20.04

Installation:

  1. Clone source files into ~/.tfenv:
    git clone https://github.com/tfutils/tfenv.git ~/.tfenv
    
  2. Add ~/.tfenv/bin to your $PATH:
    echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> ~/.bash_profile
    
  3. Create symlink to the executable:
    sudo ln -s ~/.tfenv/bin/* /usr/local/bin
    

Usage:

  1. To get installed version:
    tfenv --version
    
  2. To get list of all available commands:
    tfenv
    
  3. To list all installed versions:
    tfenv list
    
  4. To list all installable versions from remote repositories:
    tfenv list-remote
    
  5. To install a specific version of Terraform use:
    tfenv install [version]
    
  6. To uninstall a specific version use:
    tfenv uninstall [version]
    
  7. To switch to a specific version use:
    tfenv use [version]
    
  8. To write the current active version to ./.terraform-version use:
    tfenv pin
    

Uninstall:

  1. Delete entry from ~/.bash_profile file:
    grep -v 'export PATH="$HOME/.tfenv/bin:$PATH"' ~/.bash_profile > ~/.bash_profile_tmp && mv ~/.bash_profile_tmp ~/.bash_profile
    
  2. Unlink symlink:
    sudo unlink /usr/local/bin/tfenv
    
  3. Delete ~/.tfenv folder:
    rm -rf ~/.tfenv/
    

Reference:

  1. .terraform-version
  2. Delete Lines in a Text File That Contain a Specific String

More from this blog

M

Maxat Akbanov's blog

259 posts

Postgraduate in Cyber Security with experience in Software Engineering and DevOps Operations.