【问题标题】:bash: terraform: command not found, export $PATH unresolvedbash:terraform:找不到命令,导出 $PATH 未解决
【发布时间】:2017-12-06 17:00:47
【问题描述】:

我在 Ubuntu 中从命令行运行 terraform(exe) 的所有努力都没有成功

~/tectonic_1.7.9-tectonic.2$ terraform init ./platforms/metal
terraform: command not found

我更改了 ~/.profile 文件

PATH="$HOME/bin:$HOME/.local/bin:$HOME/bin/tectonic_1.7.9-tectonic.2:$PATH"

和后面的符号链接

/usr/bin# ls -l terraform
lrwxrwxrwx 1 root root 39 dec  6 16:29 terraform -> /home/milenko/tectonic_1.7.9-tectonic.2

我不明白出了什么问题。如果我尝试 Asere 的建议

ln -s /home/milenko/tectonic_1.7.9-tectonic.2/terraform /usr/bin/terraform
ln: failed to create symbolic link '/usr/bin/terraform/terraform': File exists

【问题讨论】:

  • 在你的例子中,/home/milenko/tectonic_1.7.9-tectonic.2 似乎是一个文件夹......你确定你不应该写像ln -s /home/milenko/tectonic_1.7.9-tectonic.2/terraform /usr/bin/terraform 这样的东西吗?
  • @Aserre 请看看我的编辑!
  • @MikiBelavista 您必须先删除旧的无效链接。 rm /usr/bin/terraform

标签: linux bash ubuntu terraform devops


【解决方案1】:

先修复,再解释:

ln -snf /home/milenko/tectonic_1.7.9-tectonic.2/terraform /usr/bin/terraform
# or equivalently:
#rm /usr/bin/terraform
#ln -s /home/milenko/tectonic_1.7.9-tectonic.2/terraform /usr/bin/terraform

目前你有/usr/bin/terraform 指向/home/milenko/tectonic_1.7.9-tectonic.2

这是不正确的,因为 terraform 二进制文件在 /home/milenko/tectonic_1.7.9-tectonic.2/terraform 中。

你需要让/usr/bin/terraform指向/home/milenko/tectonic_1.7.9-tectonic.2/terraform

让我们了解这里发生了什么:

ln -s /home/milenko/tectonic_1.7.9-tectonic.2/terraform /usr/bin/terraform
ln: failed to create symbolic link '/usr/bin/terraform/terraform': File exists

为什么命令失败? 由于/usr/bin/terraform 存在, 它指向/home/milenko/tectonic_1.7.9-tectonic.2, 以上评论不会尝试替换/usr/bin/terraform, 但尝试创建/usr/bin/terraform/terraform。 而且由于/usr/bin/terraform指向/home/milenko/tectonic_1.7.9-tectonic.2,所以/usr/bin/terraform/terraform已经存在,实际上和/home/milenko/tectonic_1.7.9-tectonic.2/terraform是一回事。 所以文件存在,命令失败。

一种解决方案是删除不正确的符号链接/usr/bin/terraform,然后重新运行ln -s /home/milenko/tectonic_1.7.9-tectonic.2/terraform /usr/bin/terraform

另一种解决方案是将-f-n 标志添加到ln, 强制替换符号链接:

ln -snf /home/milenko/tectonic_1.7.9-tectonic.2/terraform /usr/bin/terraform

【讨论】:

    【解决方案2】:

    2022 年 1 月更新:

    您最好在The Official Terraform Website 之后再次安装 Terraform。但是例如,要为 UbuntuDebian 安装 Terraform,我们需要运行如下所示的 4 个命令,这很麻烦。而且每次打开终端都需要运行以下4条命令,比较麻烦:

    sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl
    
    curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
    
    sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
    
    sudo apt-get update && sudo apt-get install terraform
    

    所以我将它们与上面的 "&&" 连接起来,如下所示,这样我们就可以在上面一次运行它们并且它工作正常。只需为 UbuntuDebian 复制、粘贴并运行以下命令:

    sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl &&
    curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - &&
    sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" &&
    sudo apt-get update && sudo apt-get install terraform
    

    我搜索了很多错误 "bash: terraform: command not found",但没有任何简单的解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-13
      • 2017-01-21
      • 1970-01-01
      • 2013-09-05
      • 2020-01-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多