duanjian4698 2014-03-02 10:02
浏览 43
已采纳

如何从源代码在我的ubuntu 12.10上安装Go

I am trying to install Go on my Ubuntu system but facing issues with old and broken installation steps. I tried using apt-get but getting the following error:

$ sudo apt-get install golang

 404  Not Found [IP: 91.189.91.13 80] 
 404  Not Found [IP: 91.189.92.200 80]
 404  Not Found [IP: 91.189.92.200 80]
 Get:5 http://archive.ubuntu.com/ubuntu/ quantal/universe golang-go amd64 2:1.0.2-2 [17.3 MB]
Fetched 24.9 MB in 2min 47s (149 kB/s)                                         
Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/perl/perl-modules_5.14.2-         13ubuntu0.2_all.deb  404  Not Found [IP: 91.189.92.200 80]
 Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/perl/perl_5.14.2-13ubuntu0.2_amd64.deb  404  Not Found [IP: 91.189.92.200 80]
 E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

I also tried installing via GVM, getting the following error:

scripts/gvm-installer) < <(curl -s https://raw.github.com/moovweb/gvm/master/bin 

-bash: curl: command not found

I am pretty new to the Go language. Please help me: how do I install Go?

  • 写回答

4条回答 默认 最新

  • duanaoshu1989 2014-03-02 10:07
    关注

    There are many ways to configure the Go development environment on your computer, and you can choose whichever one you like. The three most common ways are as follows.

    Official installation packages: The Go team provides convenient installation packages in Windows, Linux, Mac and other operating systems. This is probably the easiest way to get started.

    Install it yourself from source code: Popular with developers who are familiar with Unix-like systems.

    Using third-party tools: There are many third-party tools and package managers for installing Go, like apt-get in Ubuntu and homebrew for Mac.

    1. Install from source code

    a) On Unix-like systems, you need to install gcc or a similar compiler. For example, using the package manager apt-get (included with Ubuntu), one can install the required compilers as follows:

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

    b) The Go team uses Mercurial to manage their source code, so you need to install this tool in order to download the Go source code.

    sudo apt-get install python-setuptools python-dev build-essential
    sudo apt-get install mercurial
    

    c) Go will install to a directory named 'go'. This directory should not exist at $GOROOT. Checkout and get the latest code by typing the below command:

    hg clone -u release https://code.google.com/p/go
    

    d) Now compile Go source code.

    cd go/src
    ./all.bash  
    

    The building and testing take some time (a few minutes) and after successful of all the tests, the following message appears:

      ALL TESTS PASSED
    ---
    Installed Go for linux/amd64 in /home/ubuntu/go.
    Installed commands in /home/ubuntu/go/bin.
    *** You need to add /home/ubuntu/go/bin to your $PATH. ***
    The compiler is 6g.
    

    e) Verify the installed Go version:

    go version
    

    f) Set Go-Environment variables

    Now we are ready to set up our workspace. The $GOPATH is a folder (or set of folders) specified by its environment variable. We must notice that this is not the $GOROOT directory where Go is installed.

    echo "export GOROOT=\$HOME/go" >> ~/.profile
    echo "export GOPATH=$HOME/gocode" >> ~/.profile
    echo "PATH=$PATH:\$GOROOT/bin" >> ~/.profile
    echo "PATH=$PATH:$GOPATH/bin" >> ~/.profile
    source ~/.profile
    

    We used ~/gocode path in our computer to store the source of our application and its dependencies. The GOPATH directory will also store the binaries of their packages.

    2. Using the standard installation packages

    Go has one-click installation packages for every supported operating system (Mac, Linux, Windows). These packages will install Go in /usr/local/go (c:\Go in Windows) by default. Of course this can be modified, but you also need to change all the environment variables manually as I've shown above.

    3. Use third-party tools

    a) GVM

    GVM is a Go multi-version control tool developed by a third-party, like rvm for ruby. It's quite easy to use. Install gvm by typing the following commands in your terminal:

    bash < <(curl -s -S -L https://raw.github.com/moovweb/gvm/master/binscripts/gvm-installer)
    

    Then we install Go using the following commands:

    gvm install go1.0.3
    gvm use go1.0.3
    

    After the process has finished, you're all set.

    b) apt-get

    Ubuntu is the most popular desktop release version of Linux. It uses apt-get to manage packages. We can install Go using the following commands.

    sudo add-apt-repository ppa:gophers/go
    sudo apt-get update
    sudo apt-get install golang-stable
    

    c) Homebrew

    Homebrew is a software management tool commonly used in Mac to manage packages. Just type the following commands to install Go.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度