如何在PowerShell中修改GOPATH [英] how to modify GOPATH in powershell
问题描述
我试图将我的项目目录添加到GOPATH中,在linux中我可以这样做
$ b
export GOPATH = $ HOME / mygo
在〜/ .bashrc中
powershell中的等价性是什么
[Environment] :: SetEnvironmentVariable(GOPATH,C:\Your\Path,User)
有一点需要注意:当我们使用
SetEnvironmentVariable
创建一个新的用户级或机器级环境变量,该变量在Windows PowerShell中运行此命令时并不总是显示出来:
Get-ChildItem Env:
或者至少它在我们重新启动PowerShell之前没有显示出来。 (或启动PowerShell的新实例。)
但是,我们可以随时使用以下命令检索新变量的值:
[Environment] :: GetEnvironmentVariable(GOPATH,User)
如果您只想要当前shell,请参阅 cmotley 的回答,并在同一篇文章中详细说明:
$ env:GOPATH =C:\Your\Path
作为 Jaykul 评论,在<$ c中设置该行$ c>%UserProfile%\ My Documents \WindowsPowerShell\profile.ps1 相当于〜\.bashrc中的一个导出
:
请参阅 Windows PowerShell配置文件。
(实际上有4个配置文件,所提及的一个配置文件仅适用于当前用户,但会影响所有的shell)
I am trying to add my project directory to GOPATH, in linux I can do
export GOPATH=$HOME/mygo
in ~/.bashrc
what is the equivalence in powershell
This should follow the way you set any Environment variable with Powershell (as described in this article):
If you want it permanent (ie will apply for any 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")
If you want it for just the current shell, as mentioned in cmotley's answer and detailed in the same article:
$env:GOPATH = "C:\Your\Path"
As Jaykul comments, setting that line in your %UserProfile%\My Documents\WindowsPowerShell\profile.ps1
is the equivalent of an export in ~\.bashrc
:
See "Windows PowerShell Profiles".
(There are actually 4 profiles, the one profile mentioned applies only to the current user, but affects all shells)
这篇关于如何在PowerShell中修改GOPATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!