Skip to content

Commit

Permalink
fix: sometimes GOBIN doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
ImSingee committed Dec 16, 2024
1 parent 964852e commit f201e0c
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ func goInstallTo(pkg, version string, dst string, showProgress bool) error {

cmd := exec.Command("go", "install", pkgWithVersion)

cmd.Env = []string{"GOBIN=" + d}
cmd.Env = append(cmd.Env, os.Environ()...)
cmd.Env = append(copyEnvWithoutGOBIN(), "GOBIN="+d)

if showProgress {
pp.Println("go install", pkgWithVersion, "...")
Expand Down Expand Up @@ -106,3 +105,18 @@ func goGetBinNameForPkg(pkg string) string {

return name
}

func copyEnvWithoutGOBIN() []string {
env := os.Environ()
copied := make([]string, 0, len(env))

for _, e := range env {
if strings.HasPrefix(e, "GOBIN=") {
continue
}

copied = append(copied, e)
}

return copied
}

0 comments on commit f201e0c

Please sign in to comment.