Hugo 服务器 - 术语 'hugo' 无法识别

Hugo server - The term 'hugo' is not recognized

我正在使用 Microsoft Visual Code(有史以来第一次)。

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

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

我运行接下来的步骤:现在在Visual Studio代码中打开一个新终端window,方法是点击“终端菜单”,然后点击“新终端”。在终端 window 中输入以下命令: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

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

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

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

感谢任何帮助。

错误意味着 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。 amperstand & 是调用运算符并告诉 Powershell 执行引用的字符串。

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

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

如果您使用 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 的文章——也许我的文章中有一些有用的信息...