duankuan5319
2011-05-16 15:33
浏览 97

在Linux(Mint)中安装Go并修改bashrc

I want to install Google's Go Language on my Linux Mint machine. I'm new to Linux so its not easy to follow some of the instructions I have read. Namely, I have been told to edit/mod the bashrc file:

 export GOROOT=$HOME/gosource
 export GOARCH=amd64
 export GOOS=linux
 export GOBIN=$HOME/bin
 export PATH=$PATH:$GOBIN

I don't know how to do this. I typed gedit ~/.bashrc

into the terminal and a blank page appeared. I put in the code and saved it. Then did

hg clone -u https://go.googlecode.com/hg/ go

to get the source code. Is this correct? Because I then tried to compile the code and a long list of errors appeared (which I don't have - I'm using a different PC at the mo unfortunately).

But if anyone can help me install Go, I'd appreciate it.

SOLUTION:

Aside from various problems mentioned and solved in the answers below, I had forgotten to install the following

sudo apt-get install bison ed gawk gcc libc6-dev make

WHich is mentioned at the top of the golang.com install page.

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

我想在我的Linux Mint机器上安装Google的Go语言。 我是Linux的新手,所以要遵循我已阅读的一些说明并不容易。 也就是说,有人告诉我编辑/修改bashrc文件:

  export GOROOT = $ HOME / gosource 
 export GOARCH = amd64 
 export GOOS = linux 
 export  GOBIN = $ HOME / bin 
导出PATH = $ PATH:$ GOBIN 
   
 
 

我不知道该怎么做。 我在终端中输入 gedit〜/ .bashrc

,然后出现空白页。 我输入代码并保存。 然后

  hg克隆了-u https://go.googlecode.com/hg/ go 
   
 
 

获取源代码。 这个对吗? 因为然后我尝试编译代码,并且出现了一长串错误(我没有这个错误,不幸的是我现在正在使用其他PC)。

但是如果有人 可以帮助我安装Go,我会很感激。

解决方案:

除了以下答案中提到和解决的各种问题之外, 忘记安装以下文件

  sudo apt-get install bison ed gawk gcc libc6-dev make 
   
 
 

在golang.com安装页面的顶部提到。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • douguiyan9164 2011-05-16 18:17
    已采纳

    Amongst other things, you tried to clone the repository to ~/go and edited ~/.bashrc to point $GOROOT to ~/gosource.

    Read the Go Getting Started instructions carefully. Either copy and paste commands or check what you type very carefully; check input very carefully before you hit enter. For commands, the $ sign represents the command prompt, don't type it. Remember, Linux is case sensitive and the distinction between / and \ is important. Check the output of commands very carefully; does the ouput make sense. Run diagnostic commands like env, pwd, which, and uname. When you see scroll bars in a Stack Overflow answer, scroll through all the code and output.

    First, set up ~/.bashrc.

    $ gedit ~/.bashrc
    
    export GOROOT=$HOME/go
    export GOARCH=amd64
    export GOOS=linux
    export GOBIN=$GOROOT/bin
    export PATH=$PATH:$GOBIN
    

    Close any open terminal windows and then open a new terminal window to check the new ~./bashrc and other values.

    $ env | grep '^\(GO\|HOME=\|PATH=\)'
    GOBIN=/home/peter/go/bin
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/peter/go/bin
    GOARCH=amd64
    HOME=/home/peter
    GOROOT=/home/peter/go
    GOOS=linux
    $ cd $GOROOT/src
    $ pwd
    /home/peter/go/src
    $ uname -a
    Linux peter 2.6.32-31-generic #61-Ubuntu SMP Fri Apr 8 18:25:51 UTC 2011 x86_64 GNU/Linux
    

    Then clone the repository to $GOROOT and you will clone to and compile from the same place.

    $ hg clone -u release https://go.googlecode.com/hg/ $GOROOT
    requesting all changes
    adding changesets
    adding manifests
    adding file changes
    added 8441 changesets with 31916 changes to 4421 files (+1 heads)
    updating to branch release-branch.r57
    2702 files updated, 0 files merged, 0 files removed, 0 files unresolved
    $ cd $GOROOT/src
    $ ./all.bash
    < SNIP OUTPUT >
    ALL TESTS PASSED
    ---
    Installed Go for linux/amd64 in /home/peter/go.
    Installed commands in /home/peter/go/bin.
    The compiler is 6g.
    $ which 6g
    /home/peter/go/bin/6g
    

    You haven't posted your output, so I can only guess what your problems are.

    For example, you say "the directory is Go", it should be "go"; since Linux is case sensitive, "Go" and "go" are different.

    If you omit the $GOROOT destination from the hg clone command or $GOROOT is not set, hg clone will default to the hg directory. For example,

    $ env | grep '^GOROOT'
    GOROOT=
    $ hg clone -u release https://go.googlecode.com/hg/ $GOROOT
    destination directory: hg
    

    Since you have GOARCH=amd64, you should be running a 64-bit version of Linux Mint on an x86_64 processor. What does your uname -a output say? You want the 6g and 6l programs to compile and link on an x86_64 processor, which should be in your $GOBIN directory, which should be in in your $PATH.

    $ env | grep '^\(GOBIN\|PATH=\)'
    GOBIN=/home/peter/go/bin
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/peter/go/bin
    $ which 6g
    /home/peter/go/bin/6g
    

    You should also have seen this by reading the end of your ./all.bash command output.

    ALL TESTS PASSED
    ---
    Installed Go for linux/amd64 in /home/peter/go.
    Installed commands in /home/peter/go/bin.
    The compiler is 6g.
    
    点赞 打赏 评论
  • dormbaf90464 2011-05-16 15:36

    Instead of

    gedit /.bashrc
    

    you should have typed

    gedit ~/.bashrc
    

    The fact that you were able to save it(?!) indicates that either you typo'd what you actually typed in your question, or you were running gedit as root. You need to run gedit as the same user (your user) that will be doing the compiling, to ensure that you edit the right file.

    点赞 打赏 评论
  • duanjia7607 2011-05-16 16:31

    There's no need to tweak the environment in the simplest case.

    After cloning, do

    cd go/src
    ./all.bash
    

    to get Go compiled. After compiling you'll be told where it's installed and how to run it. Then you might want to really modify your environment to update the PATH variable. But this question is really out of scope of the Go language, so do what Robin Green suggested.

    P.S. The Debian packages for golang have recently been uploaded to unstable (see this bug), so may be it would be a better idea to grab the source package and build a real Debian package(s) from it.

    点赞 打赏 评论

相关推荐