How to install Go on my ubuntu 12.10 from source code

huangapple go评论82阅读模式
英文:

How to install Go on my ubuntu 12.10 from source code

问题

我正在尝试在我的Ubuntu系统上安装Go,但在旧的和损坏的安装步骤上遇到了问题。我尝试使用apt-get命令,但出现以下错误:

$ 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?

我还尝试通过GVM安装,但出现以下错误:

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

-bash: curl: command not found

我对Go语言还不太熟悉。请帮助我:如何安装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?

答案1

得分: 3

在计算机上配置Go开发环境有很多种方式,你可以选择任何一种你喜欢的方式。以下是三种最常见的方式:

官方安装包:
Go团队在Windows、Linux、Mac等操作系统中提供了方便的安装包。这可能是最简单的入门方式。

从源代码自己安装:
对于熟悉类Unix系统的开发人员来说很受欢迎。

使用第三方工具:
有许多第三方工具和软件包管理器可用于安装Go,比如Ubuntu中的apt-get和Mac中的homebrew。

1. 从源代码安装

a) 在类Unix系统上,你需要安装gcc或类似的编译器。例如,使用包管理器apt-get(Ubuntu中包含)可以安装所需的编译器,命令如下:

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

b) Go团队使用Mercurial来管理他们的源代码,所以你需要安装这个工具以便下载Go源代码。

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

c) Go将安装到一个名为'go'的目录中。这个目录在$GOROOT下不应该存在。通过输入以下命令来检出并获取最新的代码:

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

d) 现在编译Go源代码。

cd go/src
./all.bash	

编译和测试需要一些时间(几分钟),在所有测试成功后,会出现以下消息:

  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) 验证已安装的Go版本:

go version

f) 设置Go环境变量

现在我们准备好设置我们的工作空间了。$GOPATH是一个由环境变量指定的文件夹(或一组文件夹)。我们必须注意这不是Go安装的$GOROOT目录。

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

我们在计算机上使用了~/gocode路径来存储我们应用程序的源代码和其依赖项。GOPATH目录还将存储其包的二进制文件。

2. 使用标准安装包

Go为每个支持的操作系统提供了一键安装包(MacLinuxWindows)。这些安装包将默认安装Go在/usr/local/go(Windows中为c:\Go)。当然,这可以修改,但你还需要手动更改所有的环境变量,就像我上面展示的那样。

3. 使用第三方工具

a) GVM

GVM是一个由第三方开发的Go多版本控制工具,类似于ruby的rvm。它非常容易使用。在终端中输入以下命令安装gvm:

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

然后我们使用以下命令安装Go:

gvm install go1.0.3
gvm use go1.0.3

完成后,你就准备好了。

b) apt-get

Ubuntu是最受欢迎的Linux桌面发行版。它使用apt-get来管理软件包。我们可以使用以下命令安装Go。

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

c) Homebrew

Homebrew是Mac中常用的软件管理工具。只需输入以下命令即可安装Go。

brew install go
英文:

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 &quot;export GOROOT=$HOME/go&quot; &gt;&gt; ~/.profile
echo &quot;export GOPATH=$HOME/gocode&quot; &gt;&gt; ~/.profile
echo &quot;PATH=$PATH:$GOROOT/bin&quot; &gt;&gt; ~/.profile
echo &quot;PATH=$PATH:$GOPATH/bin&quot; &gt;&gt; ~/.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 &lt; &lt;(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

答案2

得分: 2

这将在您的主目录中安装Go。

# 更新软件包列表
sudo apt-get update -q

# 安装软件包
sudo apt-get install -qy build-essential curl git

# 安装Go源码
mkdir ~/gosrc &amp;&amp; curl -s https://go.googlecode.com/files/go1.2.src.tar.gz | tar -v -C ~/gosrc -xz

# 从源码构建Go
cd ~/gosrc/go/src &amp;&amp; ./make.bash

然后,您需要设置GOPATH(可选地设置GOROOT)变量,并修改您的PATH以包含bin目录,以便正确使用工具。有关更多详细信息,请参阅如何编写Go代码

英文:

This will install Go in your home directory.

# Update package lists
sudo apt-get update -q

# Install packages
sudo apt-get install -qy build-essential curl git

# Install Go source
mkdir ~/gosrc &amp;&amp; curl -s https://go.googlecode.com/files/go1.2.src.tar.gz | tar -v -C ~/gosrc -xz

# Build Go from source
cd ~/gosrc/go/src &amp;&amp; ./make.bash

You then need to setup the GOPATH (and optionally GOROOT) variable, and modify your PATH to include the bin directories in order to properly use the tools. See How to Write Go Code for more details.

答案3

得分: 1

我使用godeb来完成这个任务,非常简单。

  1. 从上面的页面下载正确版本的godeb。
  2. 运行./godeb install

这将从golang.org下载二进制版本,然后将其转换为.deb文件并进行安装。

这个工具是由Gustavo Niemeyer编写的,他在Canonical工作,并曾负责维护Launchpad中的Go PPA,但现在已经放弃了PPA,转而使用这个工具。所以我可以说这是官方推荐的方法!

英文:

I use godeb for this which is very easy

  1. Download the correct version of godeb from the page above
  2. ./godeb install

This downloads the binary release from golang.org then converts it into a .deb then installs it.

It was written by Gustavo Niemeyer who works for Canonical and used to maintain the Go PPA in Launchpad but has given it up in favour of this. So I'd say this is about as official as it comes!

答案4

得分: 0

  1. 从网站https://code.google.com/p/go/downloads/list?q=OpSys-FreeBSD+OR+OpSys-Linux+OR+OpSys-OSX+Type-Archive下载Go的二进制包。
  2. 解压缩并将其移动到/usr/local/go目录下(例如:sudo mv go1.2 /usr/local/go)。
  3. 创建$HOME/go目录。
  4. 在你的.bashrc文件中添加以下内容:
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

完成后就可以了!

英文:
  1. Simply download a binary package of go from the website:
    https://code.google.com/p/go/downloads/list?q=OpSys-FreeBSD+OR+OpSys-Linux+OR+OpSys-OSX+Type-Archive

  2. untar it and move it to be /usr/local/go (i.e. sudo mv go1.2 /usr/local/go)

  3. mkdir $HOME/go

  4. add to your .bashrc:

export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

you should be good!

huangapple
  • 本文由 发表于 2014年3月2日 18:02:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/22126184.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定