douchen4534
2015-09-17 14:38
浏览 43

在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"

图片转代码服务由CSDN问答提供 功能建议

我试图在Ubuntu上设置go dev环境,但没有运气。 请按照此处 https://github.com/golang/go/wiki/Ubuntu < / p>

  sudo apt-get install golang 
   
 
 

然后我

 < 代码> mkdir $ HOME / golang 
export GOPATH = $ HOME / golang 
   
 
 

没有骰子。 即使执行诸如 go version 之类的简单操作也会引发以下错误:

  go:找不到GOROOT目录:/ usr / local / opt / go / libexec  
   
 
 

我在网上看到的每个地方都说根本不设置 GOROOT 。 请帮助,我不知道从这里去哪里。 这是在新VM上的全新安装。


  GOARCH =“ amd64” 
GOBIN =“” 
GOCHAR =“ 6” 
GOEXE =  “” 
GOHOSTARCH = “AMD64” 
GOHOSTOS = “LINUX” 
GOOS = “LINUX” 
GOPATH = “/家/艾萨克/ golang” 
GORACE = “” 
GOROOT =“在/ usr /本地的/ opt /去/ libexec目录 “ 
GOTOOLDIR =” / usr / local / opt / go / libexec / pkg / tool / linux_amd64“ 
TERM =” dumb“ 
CC =” gcc“ 
GOGCCFLAGS =”-g -O2 -fPIC -m64 -pthread“ \  nCXX =“ 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!!

    点赞 打赏 评论
  • douping5015 2015-09-18 04:27

    On my ubuntu machine i installed go by following those simple steps:

    $ wget https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz
    $ sudo tar -C /usr/local -xzf go1.4.2.linux-amd64.tar.gz
    $ rm go1.4.2.linux-amd64.tar.gz
    

    Add go to your $PATH variable

    $ mkdir $HOME/go
    $ nano ~/.bashrc
    export GOPATH=$HOME/go
    export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
    $ source ~/.bashrc
    

    This Works just fine.

    点赞 打赏 评论
  • duanfu2562 2017-11-21 18:24

    For golang-go from the Ubuntu repositories

    This answer refers to the golang-go package from the default Ubuntu repositories, not the go-lang package that can be installed using ubuntu-make.

    The key to understanding your question is the following line:

    GOROOT="/usr/local/opt/go/libexec"
    

    If you typed the command echo $GOROOT it would return:

    /usr/local/opt/go/libexec
    

    This is not what you want GOROOT to be in an installation of golang-go from the default Ubuntu repositories. In a default golang-go installation in Ubuntu GOROOT refers to the root of the directories where go is installed. Running the command which go returns /usr/bin/go and examining the /usr/bin/go file reveals that it is symlinked to the go executable file located at /usr/lib/go-1.6/bin/go . There is your missing GOROOT. If you installed golang-go using the command sudo apt install golang-go GOROOT is the root directory of all the go files that are installed by golang-go; it is /usr/lib/go-1.6 !

    It remains to apply the change in GOROOT to /etc/environment by editing the environment file in nano text editor with the following command:

    sudo nano /etc/environment
    

    Right after where it says PATH=" in /etc/environment insert the following text to add it to the PATH:

    /usr/lib/go-1.6:
    

    Press the keyboard combination Ctrl+O and after that press Enter to save the file being edited in nano to its current location. Press the keyboard combination Ctrl+X to exit nano.

    The : character after /usr/lib/go-1.6 is the delimiter character which separates the go path from the next path. It is advisable to check your work for accuracy with the following command:

    cat /etc/environment
    

    Now that you have updated the PATH you need to reload /etc/environment by logging out and logging back in.

    点赞 打赏 评论

相关推荐 更多相似问题