udhos / update-golang

update-golang is a script to easily fetch and install new Golang releases with minimum system intrusion
MIT License
1.86k stars 227 forks source link

`fatal: not a git repository (or any of the parent directories): .git` #29

Closed englianhu closed 3 years ago

englianhu commented 3 years ago
-fatal: not a git repository (or any of the parent directories): .git

Can you please post those error logs at https://github.com/udhos/update-golang/issues

and also please include the output for go env ?

source: https://gist.github.com/nikhita/432436d570b89cab172dcf2894465753#gistcomment-3870962

+:~/update-golang$ sudo ./update-golang.sh
[sudo] password for englianhu: 
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
-can't load package: package .: no Go files in /home/englianhu
-can't load package: package .: no Go files in /home/englianhu
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
-can't load package: package .: no Go files in /home/englianhu
-can't load package: package .: no Go files in /home/englianhu
update-golang.sh: unsudo: running_as_root:englianhu: tee /tmp/hello-tmp5siDP3Qg.go
-fatal: not a git repository (or any of the parent directories): .git
-can't load package: package .: no Go files in /home/englianhu
-can't load package: package .: no Go files in /home/englianhu
update-golang.sh: testing: /usr/local/go/bin/go run /tmp/hello-tmp5siDP3Qg.go
update-golang.sh: unsudo: running_as_root:englianhu: /usr/local/go/bin/go run /tmp/hello-tmp5siDP3Qg.go
-fatal: not a git repository (or any of the parent directories): .git
-can't load package: package .: no Go files in /home/englianhu
-can't load package: package .: no Go files in /home/englianhu
update-golang.sh: hello, world - go1.17
update-golang.sh: /usr/local/go/bin/go run /tmp/hello-tmp5siDP3Qg.go: SUCCESS
update-golang.sh: running_as_root: yes
-fatal: not a git repository (or any of the parent directories): .git
-can't load package: package .: no Go files in /home/englianhu
-can't load package: package .: no Go files in /home/englianhu
update-golang.sh: recursively forcing build cache [/home/englianhu/.cache/go-build] ownership to 1000:1000
update-golang.sh: cleanup: /tmp/profile-tmpW8occx3O
+:~/update-golang$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/englianhu/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/englianhu/golang"
GOPROXY=""
GORACE=""
GOROOT="/usr"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/gcc/x86_64-linux-gnu/9"
GCCGO="/usr/bin/x86_64-linux-gnu-gccgo-9"
CC="x86_64-linux-gnu-gcc-9"
CXX="x86_64-linux-gnu-g++-9"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build397497347=/tmp/go-build -gno-record-gcc-switches -funwind-tables"
englianhu commented 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
udhos commented 3 years ago

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?

englianhu commented 3 years ago

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