簡體   English   中英

GOPATH 環境變量未在 Fish shell 中設置?

[英]GOPATH environment variable not getting set in the Fish shell?

我有一個~/.config/fish/config.fish ,其中包含以下幾行:

set PATH $PATH (go env GOPATH)/bin
set -x GOPATH (go env GOPATH)

如果我只是在命令行中運行go env GOPATH ,我會得到默認位置( ~/go ):

> go env GOPATH
/Users/kurt/go

但是,沒有定義$GOPATH環境變量:

> echo $GOPATH

為什么沒有設置$GOPATH環境變量?

set -x只會影響您當前的 session。 一旦您注銷 session,導出將 go 消失。

set --export --global將在所有正在運行的魚會話中導出您的環境,但是它是短暫的,並且在您注銷后不會持續存在。

set --export --universal將在所有運行的魚會話中導出您的環境,並且是持久的。

-g or --global
       Causes the specified shell variable to be given a global scope. 
Global variables don't disappear and are available to all functions 
running in the same shell.  They can even be modified.

-U or --universal
       Causes  the  specified shell variable to be given a universal scope. 
If this option is supplied, the variable will be shared between all the current 
user's fish instances on the current computer, and will be preserved across 
restarts of the shell

如果您正在運行當前版本的 fish,您可以使用內置的fish_add_path (go env GOPATH)/bin一次,它就完成了,您不必將它放在 conf 文件中。

要將 Go 路徑添加到您的 Fish shell,請將以下行添加到您的 config.fish:

set -x GOPATH $HOME/go
set -x PATH $PATH $GOPATH/bin

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM