【问题标题】:Hugo server - The term 'hugo' is not recognizedHugo 服务器 - 无法识别术语“hugo”
【发布时间】:2021-01-14 02:53:06
【问题描述】:

我正在使用 Microsoft Visual Code(第一次)。

我正在尝试按照这些步骤https://www.dsquintana.blog/create-an-academic-website-free-easy-2020/ 使用学术主题构建网站

安装 Hugo Extended 后scoop install git go hugo-extended

我运行接下来的步骤:现在在 Visual Studio Code 中打开一个新的终端窗口,方法是点击“终端菜单”,然后点击“新终端”。在终端窗口中输入以下命令:hugo server

我收到这条消息

hugo : The term 'hugo' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if  
a path was included, verify that the path is correct and try again.
At line:1 char:1
+ hugo server
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (hugo:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Hugo 位于:C:\Users\CHRIS\scoop\apps\hugo-extended

网站是:C:\Users\CHRIS\OneDrive\Website\Website\starter-academic.github\starter-academic>

是否需要移动 Hugo 文件夹或添加路径?如果是这样,我该如何添加路径/文件夹?

感谢任何帮助。

【问题讨论】:

    标签: powershell visual-studio-code hugo


    【解决方案1】:

    该错误意味着 Powershell 不知道 Hugo 的安装位置。有一个系统设置 PATH,它定义了 Powershell(和 CMD shell)在哪些目录中查找可执行文件。由于 Powershell 不知道 Hugo 的位置,它会给出你遇到的错误。

    现在,有几个解决方案:

    1. 将 Hugo 添加到路径
    2. 使用绝对路径
    3. 设置别名

    在某些情况下,将 Hugo 的目录添加到系统范围的路径是有意义的。这些步骤在Superuser answer 中有详细记录。通常这不是最好的方法,因为路径有最大长度,并且在那里塞很多东西不是最佳做法。

    使用绝对路径意味着不是hugo server,而是& "C:\Users\CHRIS\scoop\apps\hugo-extended\hugo" server。符号& 是调用运算符,它告诉Powershell 执行引用的字符串。

    设置别名将引入一个新命令,该命令是现有程序或命令的别名。对于 Hugo,您可以使用 set-alias -name hugo C:\Users\CHRIS\scoop\apps\hugo-extended\hugo。当您在同一个 Powershell 提示符中键入 hugo 时,Powershell 知道 hugo 是指向可执行文件实际位置的别名。

    可以通过脚本设置别名,或者将其定义保存在Powershell profile。

    【讨论】:

      【解决方案2】:

      如果您使用 scoop 安装了 hugo-extended,它应该会自动出现在您的路径上。我建议您关闭所有打开的 VS Code 终端(通过单击“Kill Terminal”垃圾桶图标)并退出 VS Code。然后重新启动 VS Code,打开一个新终端,然后运行:

      hugo version
      

      如果hugo 现在不在您的路径上,请告诉我们。

      我在Scoop: A Windows Package Manager (Featuring Hugo & Figlet Examples) 中写过关于 scoop 和 hugo 的文章——也许我的文章中有一些有用的信息...

      【讨论】:

        猜你喜欢
        • 2022-06-11
        • 1970-01-01
        • 2020-03-19
        • 2018-12-21
        • 2020-02-14
        • 2020-03-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多