Golang installation

2019-09-22 06:38发布

I just followed the installation guide for golang (ubuntu 16). I extracted the archive at /etc/usr I added env variable in /home/user/.profile I just tested a basic go build on the hello world code.

I get the following error:

The program 'go' is currently not installed. You can install it by typing: sudo apt install golang-go

Why does it ask me to install it (again?)?

3条回答
smile是对你的礼貌
2楼-- · 2019-09-22 07:25

There are paths which needs to be set correctly for you go installation to work

  1. GOROOT points to directory where go is installed

    export GOROOT=/usr/lib/go

  2. GOPATH points to you workspace directory

    export GOPATH=$HOME/go

  3. These paths need to be added in global path variable.

    export PATH=$PATH:$GOROOT/bin

查看更多
Anthone
3楼-- · 2019-09-22 07:38

You need to put the go executable in your system path. which you can do by

export PATH=$PATH:/etc/usr/go/bin

You can put the same in /home/user/.profile

查看更多
男人必须洒脱
4楼-- · 2019-09-22 07:45

The location of the binary go is not in your path. Ubuntu does not find it and suggests to install it. Add this line to your file /etc/profile, or better $HOME/.profile:

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

This is documented in the docs: https://golang.org/doc/install#install

If you want to try this solution before editing any files, you can just execute the above command and try to execute the go command in the shell.

查看更多
登录 后发表回答