Skip to content

Commit 50c8f58

Browse files
authored
fix: improve setup instructions and enforce consistent GOBIN usage (#152)
* docs: enhance instructions for updating shell startup * feat: always use GOBIN for consistency (#151) Previously, when GOBIN was empty, default packages listed in $ASDF_GOLANG_DEFAULT_PACKAGES_FILE were installed to $ASDF_INSTALL_PATH/packages/bin. This could cause confusion, as user-installed binaries might end up in different locations. This commit ensures that GOBIN is always set, so all binaries are consistently installed into $ASDF_INSTALL_PATH/bin. Additionally, the use of $ASDF_INSTALL_PATH/packages/bin is deprecated to prevent inconsistencies. Closes #151 Signed-off-by: Marko Kungla <[email protected]> --------- Signed-off-by: Marko Kungla <[email protected]>
1 parent e2527a3 commit 50c8f58

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

README.md

+19-13
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,31 @@ asdf plugin add golang https://github.com/asdf-community/asdf-golang.git
2323

2424
## Use
2525

26-
Check the [asdf](https://github.com/asdf-vm/asdf) readme for instructions on how to install & manage versions of go.
26+
To ensure the Golang environment variables are correctly set when using the `asdf` Go plugin (`asdf-golang`), you should source the appropriate `set-env` script for your shell. This is particularly important if you've customized the `asdf` data directory using the `ASDF_DATA_DIR` environment variable. Below are instructions for various shells:
2727

28-
## `GOROOT`
28+
- **Zsh (`.zshrc`):**
2929

30-
To set `GOROOT` in your shell's initialization add the following:
30+
```bash
31+
. ${ASDF_DATA_DIR:-$HOME/.asdf}/plugins/golang/set-env.zsh
32+
```
3133

32-
**zsh shell**
33-
`. ~/.asdf/plugins/golang/set-env.zsh`
34+
- **Bash (`.bashrc`):**
3435

35-
**fish shell**
36-
`source ~/.asdf/plugins/golang/set-env.fish`
36+
```bash
37+
. ${ASDF_DATA_DIR:-$HOME/.asdf}/plugins/golang/set-env.bash
38+
```
3739

38-
**nushell shell**
39-
Add this to your env.nu
40-
`source ('~/.asdf/plugins/golang/set-env.nu')`
40+
- **Fish (`config.fish`):**
4141

42-
**bash shell**
43-
Add this to your .bashrc:
44-
`. ~/.asdf/plugins/golang/set-env.bash`
42+
```fish
43+
source (echo $ASDF_DATA_DIR | if test -z $it; echo $HOME/.asdf; else echo $it; end)/plugins/golang/set-env.fish
44+
```
45+
46+
- **Nushell (`env.nu`):**
47+
48+
```nu
49+
source (if ($env.ASDF_DATA_DIR | empty?) { echo $nu.env.HOME/.asdf } { echo $env.ASDF_DATA_DIR })/plugins/golang/set-env.nu
50+
```
4551

4652
## When using `go get` or `go install`
4753

bin/exec-env

+4
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ if [ "${ASDF_INSTALL_VERSION}" != 'system' ]; then
88
if [[ "unset" == "${GOPATH:-unset}" ]]; then
99
export GOPATH=$ASDF_INSTALL_PATH/packages
1010
fi
11+
12+
if [[ "unset" == "${GOBIN:-unset}" ]]; then
13+
export GOBIN=$ASDF_INSTALL_PATH/bin
14+
fi
1115
fi

bin/install

+2
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ install_default_go_pkgs() {
5151

5252
GOROOT="$ASDF_INSTALL_PATH/go" \
5353
GOPATH="$ASDF_INSTALL_PATH/packages" \
54+
GOBIN="$ASDF_INSTALL_PATH/bin" \
5455
PATH="$go_path:$PATH" \
5556
go install "$name" >/dev/null && rc=$? || rc=$?
5657
else
5758
GOROOT="$ASDF_INSTALL_PATH/go" \
5859
GOPATH="$ASDF_INSTALL_PATH/packages" \
5960
PATH="$go_path:$PATH" \
61+
GOBIN="$ASDF_INSTALL_PATH/bin" \
6062
go get -u "$name" >/dev/null && rc=$? || rc=$?
6163
fi
6264

bin/list-bin-paths

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env bash
22

3-
echo -n "bin go/bin packages/bin"
3+
echo -n "bin go/bin"

0 commit comments

Comments
 (0)