douchen4534 2015-09-17 14:38
浏览 48
已采纳

在Ubuntu上安装

I am trying to setup a go dev environment on Ubuntu, and having no luck. Following directions here https://github.com/golang/go/wiki/Ubuntu

sudo apt-get install golang

Then I

mkdir $HOME/golang
export GOPATH=$HOME/golang

No dice. Even doing something simple like go version throws the following error:

go: cannot find GOROOT directory: /usr/local/opt/go/libexec

Everywhere I look online says simply not to set GOROOT. Please help, I don't understand where to go from here. This is a fresh install on a fresh VM.


GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/isaac/golang"
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/linux_amd64"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CXX="g++"
CGO_ENABLED="1"
  • 写回答

3条回答 默认 最新

  • dongxianrang9269 2015-09-18 19:33
    关注

    So I eventually figured this out, and boy was it dumb on my part. I had a script that was effecting $GOROOT, and learned alot. Here are the big lessons:

    • Do NOT use sudo apt-get install golang it is out of date and doing so means you now have to revert the install. sudo apt-get install golang-go is also out of date. Just don't use apt-get.
    • sudo apt-get purge golang does not reset environment variables or delete all go related folders.
    • unset GOPATH GOHOME GOROOT is important cleanup before trying another install

    • ONLY install via tar.gz from the golang website

    • GOROOT means the folder where go's internal files live, so basically where ever the contents of the tar.gz lives on your system. Typically /usr/local/go
    • GOHOME does not need to be set. If you set it, use unset
    • GOPATH is the location of your workspace, you need to mkdir to create that folder as well as set the GOPATH environment variable.
    • Your path needs to included $GOROOT/bin:$GOPATH/bin for the setup to function.

    Usage of custom scripts that effect .zshrc or bashrc or profile should not contain setting of $GOROOT!!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用