gpt4 book ai didi

powershell - 如何在powershell中修改GOPATH

转载 作者:IT王子 更新时间:2023-10-29 01:11:49 25 4
gpt4 key购买 nike

我正在尝试将我的项目目录添加到 GOPATH,在 linux 中我可以做到

在 ~/.bashrc 中导出 GOPATH=$HOME/mygo

powershell中的等价物是什么

最佳答案

这应该遵循您使用 Powershell 设置任何环境变量的方式(如 this article 中所述):

如果您希望它永久存在(即适用于任何 future 的 shell):

[Environment]::SetEnvironmentVariable("GOPATH", "C:\Your\Path", "User")

One thing to watch out for: when we used SetEnvironmentVariable to create a new user- or machine-level environment variable that variable didn’t always show up when we ran this command in Windows PowerShell:

Get-ChildItem Env:

Or at least it didn’t show up until we restarted PowerShell. (Or started up a new instance of PowerShell.)
However, we could retrieve the value of the new variable at any time by using this command:

[Environment]::GetEnvironmentVariable("GOPATH","User")

如果您只需要当前 shell,如 cmotley 中所述的 answer并在同一篇文章中详细介绍:

$env:GOPATH = "C:\Your\Path"

作为Jaykul注释,在 %UserProfile%\My Documents\WindowsPowerShell\profile.ps1 中设置该行等同于在 ~\.bashrc 中导出:
参见“Windows PowerShell Profiles”。
(实际上有4个配置文件,提到的一个配置文件仅适用于当前用户,但影响所有shell)

关于powershell - 如何在powershell中修改GOPATH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12587253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com