Sent to you by l5g via Google Reader:
via LinuxTree by noreply@blogger.com (Gautham Raj) on 11/15/09
The "Go" programming language is a new programming language coming from Google. Its is primarily aimed towards system development.
1. Install mercurial (source code management tool) to fetch the "Go" source code :
$sudo apt-get install mercurial
2. Installing other stuff that you need to build "Go" :
$sudo apt-get install bison gcc libc6-dev ed make
3. Create a folder called "go" in your home directory for all our "Go" files ** :
$cd ~
$mkdir $HOME/go
$mkdir $HOME/go/bin
$mkdir $HOME/go/src
$mkdir $HOME/go
$mkdir $HOME/go/bin
$mkdir $HOME/go/src
4. Setup some environment variables
$export GOROOT=$HOME/go/src
$export GOARCH=386
$export GOOS=linux
$export GOBIN=$HOME/go/bin
$export PATH=$PATH:$GOBIN
$export GOARCH=386
$export GOOS=linux
$export GOBIN=$HOME/go/bin
$export PATH=$PATH:$GOBIN
(Valid values for GOARCH are amd64 (for 64-bit x86), 386 (for 32-bit x86) and arm (for 32-bit ARM)
5. Fetch the "Go" source code using the mercurial tool that we installed in first step :
$hg clone -r release https://go.googlecode.com/hg/ $GOROOT
This takes around 25 minutes on a 256kbps connection.
6. Build "Go" using :
$cd $GOROOT/src
$./all.bash
$./all.bash
7. If everything is good to "Go" then it will finish by printing :
— cd ../test
N known bugs; 0 unexpected bugs
N known bugs; 0 unexpected bugs
8. We are ready to "Go"
The binaries are available in your $HOME/go/bin directory. You can add it to your bash shell path permanently by adding these line to your ~/.bashrc file :

export GOROOT=$HOME/go/src
export GOARCH=386
export GOOS=linux
export GOBIN=$HOME/go/bin
export PATH=$PATH:$HOME/go/bin
export GOARCH=386
export GOOS=linux
export GOBIN=$HOME/go/bin
export PATH=$PATH:$HOME/go/bin
9. Depending on the GOARCH that you selected in step 4, the "Go" executables are :
386 => 8g (compiler), 8l (linker)
amd64 => 6g (compiler), 6l (linker)
ARM => 5g (compiler), 5l (linker)
amd64 => 6g (compiler), 6l (linker)
ARM => 5g (compiler), 5l (linker)
(note : its small letter "L" and not number 1)
All these "Go" executables are available at $HOME/go/bin directory.
Detailed instruction available at "Go" website http://golang.org/doc/install.html
——————————
Lets compile out first "Go" program.
1. Open any text editor and create a file called "hello.go" with the following content :
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
2. Depending on the architecture the commands will be different. Since I am using the 386 version, it is 8g (compiler) and 8l (linker) in my case. See above (step 9) which command to use for your case :
$8g hello.go
$8l hello.8
$8l hello.8
(Again note : It is small letter "L" and not number 1, as in 8l)
3. An executable called ./8.out is placed in the same directory.
Now, run our first "Go" programs as :
$./8.out

Please leave comments incase of any doubts.
** One advantage of installing "Go" source in $HOME/go/src and binary in $HOME/go/bin is that you can keep updating to the latest version of "Go". Just delete all the files $HOME/go/bin and rebuild "Go" using the same procedure mentioned above when you want to update to newer versions of "Go".
$cd $HOME/go/src
$hg update tip (to update your source code to the latest version available)
UPDATES :
1. If you are getting this error :
"hello.go:3: fatal error: can't find import: fmt"
Then you need to verify whether all the Go shell variables are correct.
Please check step no. 4 and 8
"hello.go:3: fatal error: can't find import: fmt"
Then you need to verify whether all the Go shell variables are correct.
Please check step no. 4 and 8
2. If you want to clean the build directory :
$cd $GOROOT/src
$./clean.bash
$cd $GOROOT/src
$./clean.bash
Things you can do from here:
- Subscribe to LinuxTree using Google Reader
- Get started using Google Reader to easily keep up with all your favorite sites
No comments:
Post a Comment