Cannot run golang snap as a non-root user

I may miss something here. I installed the go snap by a root user.

snap install --classic go

Then after I switched to a normal user, say ubuntu, it cannot launch the go program as the root did.

Here is what root user see:

root@v1:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
root@v1:~# go version
go version go1.9 linux/amd64
root@v1:~# go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GORACE=""
GOROOT="/snap/go/727"
GOTOOLDIR="/snap/go/727/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
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"

And here is what ubuntu user see:

ubuntu@v1:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
ubuntu@v1:~$ go version
The program 'go' is currently not installed. To run 'go' please ask your administrator to install the package 'golang-go'
ubuntu@v1:~$ go env
The program 'go' is currently not installed. To run 'go' please ask your administrator to install the package 'golang-go'

However, the ubuntu user can launch the go program by specify the path:

ubuntu@v1:~$ /snap/bin/go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/ubuntu/go"
GORACE=""
GOROOT="/snap/go/727"
GOTOOLDIR="/snap/go/727/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
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"
ubuntu@v1:~$ /snap/bin/go version
go version go1.9 linux/amd64

What am I missing? Should I manually put /snap/bin to /etc/profile so every user on the system can use the go snap?

How was that ubuntu install created ? normally snapd puts a profile.d snippet in place to extend your PATH for a user…

That said, if you did not have snapd installed before, you need to log out and back in after installing it to make the profile change take effect.

1 Like

Thank you for the reply.

The hint of /etc/profile.d/apps-bin-path.sh really helped me here. I simply su ubuntu to tested the result :joy_cat:, which should be su -l ubuntu, so the /etc/profile.d/* are not sourced.

It’s my bad. Thank you. :smiley_cat: