my os is Kali.First i enter go
,shell told me go command not found
└─$ go
Command 'go' not found, but can be installed with:
sudo apt install gccgo-go
sudo apt install golang-go
so i sudo apt install golang-go
and it told me golang-go is already latest version,but go
was still not found.And i google to knows sometime it will have a floder /usr/local/go
but it not have one.
┌──(highway㉿highway)-[/usr/local]
└─$ ll
drwxr-xr-x 2 root root 4096 5月 16 13:27 bin
drwxr-xr-x 2 root root 4096 2月 8 01:26 etc
drwxr-xr-x 2 root root 4096 2月 8 01:26 games
drwxr-xr-x 2 root root 4096 2月 8 01:26 include
drwxr-xr-x 5 root root 4096 4月 23 17:28 lib
lrwxrwxrwx 1 root root 9 4月 23 17:28 man -> share/man
drwxr-xr-x 3 root root 4096 4月 24 08:09 samba
drwxr-xr-x 2 root root 4096 2月 8 01:26 sbin
drwxr-xr-x 7 root root 4096 4月 24 08:09 share
drwxr-xr-x 2 root root 4096 2月 8 01:26 src
so i locate go
and find /usr/lib/go
and cd /usr/lib/go/bin
┌──(highway㉿highway)-[/usr/lib/go]
└─$ ls
api bin doc misc pkg src test VERSION
┌──(highway㉿highway)-[/usr/lib/go/bin]
└─$ ll
-rwxr-xr-x 1 root root 10225816 5月 15 03:22 go
-rwxr-xr-x 1 root root 2281848 5月 15 03:22 gofmt
┌──(highway㉿highway)-[/usr/lib/go/bin]
└─$ ./go version
go version go1.18.2 linux/amd64
┌──(highway㉿highway)-[/usr/lib/go/bin]
└─$ ./go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/highway/.cache/go-build"
GOENV="/home/highway/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/highway/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/highway/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.18"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.18/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g "
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
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-build3356979286=/tmp/go-build -gno-record-gcc-switches"
it work,but why go
is still not found?
┌──(highway㉿highway)-[/usr/lib/go/bin]
└─$ go
Command 'go' not found, but can be installed with:
sudo apt install gccgo-go
sudo apt install golang-go
what different between floder /usr/lib/go/bin
and /usr/local/go
?if there were not different what can i do to use go
instead of cd /usr/lib/go/bin && ./go
.
CodePudding user response:
You need to append go's bin directory to your PATH environment variable. Add this line at the end of ~/.bashrc
:
export PATH=$PATH:/usr/lib/go/bin
CodePudding user response:
An alternative to @emilianolch solution is to create symlinks in /usr/local/bin
. And you properly want all the binaries in /usr/lib/go/bin
linked, so:
sudo ln -s /usr/lib/go/bin/* /usr/lib/bin/
Should work right away without restarting terminal.
PRO: Go
binaries appear as they are like other distro. May work better with other tools like VS Code.
CON: Have to ln
again if more Go
tools are installed via apk
in future. (Only new ones, not needed if reinstalling/upgrading existing ones)