user3370371
user3370371

Reputation: 33

How to install Go on my ubuntu 12.10 from source code

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?

Upvotes: 2

Views: 1838

Answers (4)

Pravin Mishra
Pravin Mishra

Reputation: 8434

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

Upvotes: 3

Nick Craig-Wood
Nick Craig-Wood

Reputation: 54079

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!

Upvotes: 1

Intermernet
Intermernet

Reputation: 19378

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 && 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 && ./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.

Upvotes: 2

Not_a_Golfer
Not_a_Golfer

Reputation: 49187

  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!

Upvotes: 0

Related Questions