7/09/2011

ลง Golang กัน

เอาบทความมาจาก wordpress ของผมเอง คิดว่าจะย้ายมาอยู่ที่นี้แล้วเลยเอามาไว้ที่นี้เลยดีกว่า อ่ะพูดมาซะยาวแล้ว เริ่มเลยดีกว่า

Golang support OS ไหนบ้าง ?


ตอบ Golang support linux, Mac OS X จะต้อง compile เอาส่วน Windows นั้นต้องลงผ่าน windows port เอาจะง่ายกว่า แต่ก็แนะนำให้ลงแบบ compile เอา เพราะว่า golang นั้นเพิ่ม function ใหม่และ เปลี่ยนแทบทุกวัน :D

เรามาเริ่มกันเลย


***เนื่องจาก Windows ต้องคุยกันยาวหน่อยเลยขอไว้ที่หลังนะก๊าฟฟ

สิ่งที่ต้องลงก่อนคือ

libc (ใน linux ต้องเชคก่อนเพราะแต่ละ distro นั้นไม่เหมือนกัน)
gcc
bison
GNU make
ed editor
awk
mercurial

ซึ่งถ้าใครใช้ ubuntu ให้พิมพ์คำสั่งตามนี้

$ sudo apt-get install bison ed gawk gcc libc6-dev make
ของ Mac OSX ให้ลง xcode

ของ windows ผมขอไว้โอกาสหน้า ดีกว่า (ตอนนี้ง่วงมาก ฮาาา)

การลง mercurial


ของ ubuntu ใช้คำสั่ง
$ sudo apt-get install mercurial
ของ Mac OSX ใช้คำสั่ง
$ sudo easy_install mercurial

โหลด Source Code

เปิด Terminal ขึ้นมาแล้วพิมพ์

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

หลังจากนั้นเข้าไป directory go/src แล้วพิม ./all.bash ตามนี้

$ cd go/src
$ ./all.bash
แล้วก็รอ....รอ.....ถ้า compile ผ่านมันจะขึ้น

ALL TESTS PASSED

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

ซึ่งถ้าเป็น 64bit compiler จะใช้ 6g ถ้าเป็น 32-bit ใช้  8g
หลังจากนั้นเราก็ทำการ export path โดยเอาคำสั่งไว้ใน ~/.profile โดยพิมพ์ตามนี้

export GOROOT=$HOME/bin
export GOBIN=$GOROOT/bin
export PATH=$GOBIN:$PATH

หลังจากนั้นให้พิม

source ~/.profile

No comments :

Post a Comment