Go doesn't work in root mode

Hello,

I have already installed go1.9.2 on my Linux system using these commands:
(for some reason I have to use this old version)

sudo tar -C /usr/local -xzf go1.9.2.linux-amd64.tar.gz
echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.profile
source ~/.profile
go version
go version go1.9.2 linux/amd64

But when I run it as root it gave me the following error:

root@mininet-vm:/home/mininet# go version
Command 'go' not found, but can be installed with:
apt install golang-go  # version 2:1.13~1ubuntu2, or
apt install gccgo-go   # version 2:1.13~1ubuntu2

How can I solve this problem?

Did you add /usr/local/go/bin to roots PATH as well?

1 Like

I’m new to golang, so I thought that it was set by default. if it is not please tell me how ??

mininet@mininet-vm:~$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mininet/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build264562574=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

I’m think this happens because you install this on your user, so, you can repeat the same echo command with the root user or configure how the documentation explain: Download and install - The Go Programming Language

You can do this by adding the following line to your $HOME/.profile or /etc/profile (for a system-wide installation):

export PATH=$PATH:/usr/local/go/bin
1 Like

Thank you so much for your help, the echo command solved my problem.