【问题标题】:How can I use multiple .exe versions on Windows 10 Command Line?如何在 Windows 10 命令行上使用多个 .exe 版本?
【发布时间】:2020-05-22 17:24:12
【问题描述】:

用例
我需要在命令行中调用/使用两个不同版本的 terraform.exe。

为什么?
Terraform 0.12 版的行为与 Terraform 0.11 非常不同。
我需要同时使用这两个版本,因为我的一些 repos 使用 v0.12,而另一些仍然使用 v0.11。

问题
如何从 CMD 调用任一版本?

CMD 示例

C:\Program Files\Terraform>terraform11 -version
Terraform v0.11.14

C:\Program Files\Terraform>terraform12 version
Terraform v0.12.20

【问题讨论】:

    标签: windows command-line path terraform exe


    【解决方案1】:

    将不同的 .exe 版本放在两个不同的子目录中:
    C:\Program Files\Terraform\v011
    C:\Program Files\Terraform\v012

    将以上目录路径放入'Path'环境变量中。
    参考:How to add a folder to `Path` environment variable in Windows 10 (with screenshots)

    使用 POWERSHELL 重命名 .exe 文件。

    #Rename v0.11 terraform.exe to 'terraform11'
    PS C:\> cd 'C:\Program Files\Terraform\v011'
    PS C:\Program Files\Terraform\v011> Rename-Item .\terraform.exe -NewName "terraform11.exe" 
    
    #Rename v0.11 terraform.exe to 'terraform12'
    PS C:\Program Files\Terraform\v011> cd 'C:\Program Files\Terraform\v012'
    PS C:\Program Files\Terraform\v012> Rename-Item .\terraform.exe -NewName "terraform12.exe"
    

    参考:https://superuser.com/questions/936294/how-to-rename-an-executable-from-its-details

    现在,使用 CMD..
    调用 'terraform12' 来执行 terraform v0.12。
    调用 'terraform11' 来执行 terraform v0.11。

    C:\>terraform12 -version
    Terraform v0.12.20
    
    C:\>terraform11 -version
    Terraform v0.11.14
    
    Your version of Terraform is out of date! The latest version
    is 0.12.20. You can update by downloading from www.terraform.io/downloads.html
    

    【讨论】:

      猜你喜欢
      • 2013-03-15
      • 2019-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-16
      • 2013-03-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多