asdf-golang: Both `$GOPATH` or `$GOROOT` are not set & request for a custom place to use my installed go version
Describe the bug
Both $GOPATH
or $GOROOT
are not.
snowflake in ~
➜ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/snowflake/Library/Caches/go-build"
GOENV="/Users/snowflake/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/snowflake/.asdf/installs/golang/1.13.8/packages"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/snowflake/.asdf/installs/golang/1.13.8/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/snowflake/.asdf/installs/golang/1.13.8/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/35/t0nqj9vd2zd735xf5d05ybzr0000gn/T/go-build082200721=/tmp/go-build -gno-record-gcc-switches -fno-common"
snowflake in ~
➜ echo $GOROOT
snowflake in ~
➜ echo $GOPATH
snowflake in ~
➜ asdf version
v0.7.6
To Reproduce Steps to reproduce the behavior:
- Install go using asdf-golang
- switch to any version of the currently installed go
- echo
$GOPATH
or$GOROOT
- return emptiness 😄
Expected behavior
To Have $GOPATH
& $GOROOT
set.
Desktop (please complete the following information):
- OS: macOS Catalina Version 10.15.3
- SHELL: zsh 5.7.1 (x86_64-apple-darwin19.0)
Additional context
Can I add a sort of Place to put my $GOPATH
& $GOROOT
as I want them to be inside of go
folder inside of my home directory and the library append on it.
eg: installing go 1.13.8 with the following environment variable ASDF_GOLANG_CUSTOM_PATH=$HOME/go
so my $GOPATH
& $GOROOT
set as the following
$GOPATH=ASDF_GOLANG_PATH/1.13.8/......
$GOROOT=ASDF_GOLANG_PATH/1.13.8/......
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 26
- Comments: 19 (5 by maintainers)
Thanks, this has indeed been helpful. I made a slight modification since the sed parsing didn’t quite work for my version of asdf.
After I thought I had it fixed with some of the previous suggestions, what ended up working for both GOPATH and GOROOT with repo-specific
.tool-versions
was this in my~/.bashrc
:it’d be good to document this in readme - what user needs to do for these to be set properly with
asdf-golang
Why do we need
GOPATH
?https://stackoverflow.com/a/53026674/7391331
@MuhmdRaouf Here is my dotfiles https://github.com/matts966/dotfiles-open.
.zshrc
.config/direnv/direnvrc
.tool-versions
.envrc
to override defaultsYou can refer official doc for other shells. https://github.com/direnv/direnv/blob/master/docs/hook.md
Edit: Maybe I misunderstood the problem. We should set additional
export
forGOPATH
andGOROOT
even withasdf-direnv
for example byexport GOROOT="$(asdf where golang)/go/"'
for your global installation.Edit2: You can add root
.envrc
withuse asdf
to setGOPATH
andGOROOT
for the global installationUsing https://github.com/asdf-community/asdf-direnv with global
.tool-versions
and.envrc
for overriding solves all the problems for me.+1 for this.
Also, it’d be great if the
GOBIN
was set. Currently I have to manually set this.I generally set my defaults in
~/.bashrc
and set project local versions in~/.envrc
and use direnv to set/unset. With the latest versions ofasdf
there is the ability to add a hook for environment variables, but it seems like it could get hairy to determine when I should override what the user already has in their env.I’ve found this alias is useful
I have this alias called in my
.zshrc
or.bashrc
files, but I find that I need to call this everytime I switch to a new project.