V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
imBossa

关于 golang 在 mac 上的环境变量设置

  •  
  •   imBossa · May 21, 2020 · 4425 views
    This topic created in 2178 days ago, the information mentioned may be changed or developed.

    修改~/.bash_profile 后 source .bash_profile

    go env 可以看到 gopath 是我设置在 bash_profile 的位置,但是关闭 shell 再打开 shell,go env 又变回原来的位置。

    ~ 下面只有.bash_profle,没有.zshrc

    希望大神帮忙解答

    Supplement 1  ·  May 22, 2020
    确认是 shell 的问题,最新的系统是 zsh,( echo $SHELL )
    12 replies    2020-05-22 23:51:59 +08:00
    yangkghjh
        1
    yangkghjh  
       May 21, 2020
    /etc/profile

    如果你无法确定 bash 配置文件的加载顺序的话
    imBossa
        2
    imBossa  
    OP
       May 21, 2020
    这是 /etc/profile 内容


    # System-wide .profile for sh(1)

    if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
    fi

    if [ "${BASH-no}" != "no" ]; then
    [ -r /etc/bashrc ] && . /etc/bashrc
    fi
    hanjingzhan
        3
    hanjingzhan  
       May 21, 2020 via Android
    brew 直接下?
    imBossa
        4
    imBossa  
    OP
       May 21, 2020
    @hanjingzhan 官网下 dmg 安装的
    Vegetable
        5
    Vegetable  
       May 21, 2020
    看起来是因为加载顺序与预期不符造成的,之前的 GOPATH 你没有移除,覆盖了你修改的 GOPATH 。建议你找到之前的变量位置。
    ls -la|grep -v ^d|grep "\."|awk '{print $9}'|xargs cat|grep GOPATH
    看一下是不是有多处
    charlie21
        6
    charlie21  
       May 21, 2020
    你的 shell 是 bash 还是 zsh 阿
    youxiachai
        7
    youxiachai  
       May 22, 2020
    mac 10.15 用 zsh.. 没有 zshrc 自己建一个吧。。
    aladdindingding
        8
    aladdindingding  
       May 22, 2020
    看你的 shell 是 zsh 还是 bash 了
    amare
        9
    amare  
       May 22, 2020
    which go, 应该是被覆盖掉了,删了就好。
    hongxi2200
        10
    hongxi2200  
       May 22, 2020
    用的是 GoLand 里的 terminal 吗?
    听上去像,因为我在 GoLand 的 terminal 里修改过 GOPROXY 在重新打开 terminal 的时候的确也出现了被恢复原样的情况。
    可能是 GoLand 的项目设置控制着 go env
    dafsic
        11
    dafsic  
       May 22, 2020
    相信我,关机,重启就好了
    imBossa
        12
    imBossa  
    OP
       May 22, 2020
    @youxiachai 是这个原因,谢谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5888 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 105ms · UTC 06:14 · PVG 14:14 · LAX 23:14 · JFK 02:14
    ♥ Do have faith in what you're doing.