Closed englianhu closed 3 years ago
1) By refer to https://stackoverflow.com/a/60695664/3806250, try to download packages from mod :~/update-golang$ go get -v all
.
2) By refer to https://juejin.cn/post/6844903986529566728, I try to :~/update-golang$ sudo micro /etc/profile.d/go.sh
and then add below lines:
# Enable the go modules feature
export GO111MODULE=on
# Set the GOPROXY environment variable
export GOPROXY=https://goproxy.io
Error still there.
+:~/update-golang$ sudo ./update-golang.sh
update-golang.sh: version 0.24
update-golang.sh: parsing with jq from https://golang.org/dl/?mode=json
update-golang.sh: find_latest: found last release: 1.17
update-golang.sh: user: uid=0(root) gid=0(root) groups=0(root)
update-golang.sh: RELEASE_LIST=https://golang.org/dl/
update-golang.sh: SOURCE=https://storage.googleapis.com/golang
update-golang.sh: DESTINATION=/usr/local
update-golang.sh: RELEASE=1.17
update-golang.sh: OS=linux
update-golang.sh: ARCH_PROBE=uname -m
update-golang.sh: ARCH=amd64
update-golang.sh: PROFILED=/etc/profile.d/golang_path.sh
update-golang.sh: CACHE=/usr/local
update-golang.sh: GOPATH=
update-golang.sh: DEBUG=
update-golang.sh:
update-golang.sh: will install golang go1.17.linux-amd64 as: /usr/local/go
update-golang.sh: https://storage.googleapis.com/golang/go1.17.linux-amd64.tar.gz is remote
update-golang.sh: no need to download - file cached: /usr/local/go1.17.linux-amd64.tar.gz
update-golang.sh: remove_old_link: found symlink for old install: /usr/local/go1.17.linux-amd64
update-golang.sh: untar: rm_dir /usr/local/go1.17.linux-amd64
update-golang.sh: untar: tar -x -f /usr/local/go1.17.linux-amd64.tar.gz
update-golang.sh: profile_path_remove: removing old settings from: /etc/profile.d/golang_path.sh
update-golang.sh: profile_path_add: issuing new /usr/local/go/bin to /etc/profile.d/golang_path.sh
update-golang.sh: profile_path_add: issuing $HOME/go/bin to /etc/profile.d/golang_path.sh
update-golang.sh: golang go1.17.linux-amd64 installed at: /usr/local/go
update-golang.sh: testing: /usr/local/go/bin/go version
update-golang.sh: unsudo: running_as_root:englianhu: /usr/local/go/bin/go version
-fatal: not a git repository (or any of the parent directories): .git
goroutine 1 [running]:
runtime..z2fdebug.Stack
../../../src/libgo/go/runtime/debug/stack.go:24
runtime..z2fdebug.PrintStack
../../../src/libgo/go/runtime/debug/stack.go:16
main.main
:0
-go: cannot find main module; see 'go help modules'
goroutine 1 [running]:
runtime..z2fdebug.Stack
../../../src/libgo/go/runtime/debug/stack.go:24
runtime..z2fdebug.PrintStack
../../../src/libgo/go/runtime/debug/stack.go:16
main.main
:0
-go: cannot find main module; see 'go help modules'
update-golang.sh: go version go1.17 linux/amd64
update-golang.sh: /usr/local/go/bin/go version: SUCCESS
update-golang.sh: unsudo: running_as_root:englianhu: mktemp -t hello-tmpXXXXXXXX
-fatal: not a git repository (or any of the parent directories): .git
goroutine 1 [running]:
runtime..z2fdebug.Stack
../../../src/libgo/go/runtime/debug/stack.go:24
runtime..z2fdebug.PrintStack
../../../src/libgo/go/runtime/debug/stack.go:16
main.main
:0
-go: cannot find main module; see 'go help modules'
goroutine 1 [running]:
runtime..z2fdebug.Stack
../../../src/libgo/go/runtime/debug/stack.go:24
runtime..z2fdebug.PrintStack
../../../src/libgo/go/runtime/debug/stack.go:16
main.main
:0
-go: cannot find main module; see 'go help modules'
update-golang.sh: unsudo: running_as_root:englianhu: tee /tmp/hello-tmp9wQDGaVg.go
-fatal: not a git repository (or any of the parent directories): .git
goroutine 1 [running]:
runtime..z2fdebug.Stack
../../../src/libgo/go/runtime/debug/stack.go:24
runtime..z2fdebug.PrintStack
../../../src/libgo/go/runtime/debug/stack.go:16
main.main
:0
-go: cannot find main module; see 'go help modules'
goroutine 1 [running]:
runtime..z2fdebug.Stack
../../../src/libgo/go/runtime/debug/stack.go:24
runtime..z2fdebug.PrintStack
../../../src/libgo/go/runtime/debug/stack.go:16
main.main
:0
-go: cannot find main module; see 'go help modules'
update-golang.sh: testing: /usr/local/go/bin/go run /tmp/hello-tmp9wQDGaVg.go
update-golang.sh: unsudo: running_as_root:englianhu: /usr/local/go/bin/go run /tmp/hello-tmp9wQDGaVg.go
-fatal: not a git repository (or any of the parent directories): .git
goroutine 1 [running]:
runtime..z2fdebug.Stack
../../../src/libgo/go/runtime/debug/stack.go:24
runtime..z2fdebug.PrintStack
../../../src/libgo/go/runtime/debug/stack.go:16
main.main
:0
-go: cannot find main module; see 'go help modules'
goroutine 1 [running]:
runtime..z2fdebug.Stack
../../../src/libgo/go/runtime/debug/stack.go:24
runtime..z2fdebug.PrintStack
../../../src/libgo/go/runtime/debug/stack.go:16
main.main
:0
-go: cannot find main module; see 'go help modules'
update-golang.sh: hello, world - go1.17
update-golang.sh: /usr/local/go/bin/go run /tmp/hello-tmp9wQDGaVg.go: SUCCESS
update-golang.sh: running_as_root: yes
-fatal: not a git repository (or any of the parent directories): .git
goroutine 1 [running]:
runtime..z2fdebug.Stack
../../../src/libgo/go/runtime/debug/stack.go:24
runtime..z2fdebug.PrintStack
../../../src/libgo/go/runtime/debug/stack.go:16
main.main
:0
-go: cannot find main module; see 'go help modules'
goroutine 1 [running]:
runtime..z2fdebug.Stack
../../../src/libgo/go/runtime/debug/stack.go:24
runtime..z2fdebug.PrintStack
../../../src/libgo/go/runtime/debug/stack.go:16
main.main
:0
-go: cannot find main module; see 'go help modules'
update-golang.sh: recursively forcing build cache [/home/englianhu/.cache/go-build] ownership to 1000:1000
update-golang.sh: cleanup: /tmp/profile-tmpFxude1Yy
It seems like you have a previous Go toolchain installed from a package manager (like yum or apt). Can you try to remove the previous golang package using the package manager and then to re-run the script?
By refer to https://stackoverflow.com/a/57634196/3806250, the linux system only read the path /usr/bin/go
, set the path will do.
#Check the path of installed go
:~$ which go
/usr/bin/go
#Remove the directory
:~$ sudo rm -rf /usr/bin/go
#Check again the go version if removed
:~$ go version
bash: /usr/bin/go: No such file or directory
#Uninstall golang
:~$ sudo apt-get purge golang-go
#To set the GOPATH regardless of the GO version add the following line to your ~/.bashrc:
:~$ go env -w GOPATH=$HOME/go
#Add path inside both file $HOME/.profile and ~/.bashrc
:~$ sudo micro $HOME/.profile #And add below line GOPATH
:~$ sudo micro ~/.bashrc #And add below line GOPATH
And add below line
#https://golang.org/doc/install#install
export GOPATH=$HOME/go
https://stackoverflow.com/a/65055094/3806250
#Reload the path's setting file of installed go
:~$ source ~/.bashrc
#Check the version of installed go
:~$ go version
go version go1.17 linux/amd64
#Check the path of installed go
:~$ which go
/home/englianhu/go/bin/go
#Check the GOPATH path of installed go
:~$ go env GOPATH
/home/englianhu/go
source: https://gist.github.com/nikhita/432436d570b89cab172dcf2894465753#gistcomment-3870962