Translate 01.1

This commit is contained in:
Tavee Khunbida
2019-01-10 08:55:16 +07:00
parent dc832e0534
commit 91ec45c2e7
2 changed files with 43 additions and 45 deletions

View File

@@ -1,112 +1,110 @@
# 1.1 Installation
# 1.1 การติดตั้ง
## Three ways to install Go
## 3 วิธีในการติดตั้ง 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.
การตั้งค่าคอมพิวเตอร์เพื่อใช้ในการพัฒนาด้วย Go นั้น มีอยู่ด้วยกันหลายวิธี และเราสามารถเลือกใช้วิธีใดก็ได้ที่ถนัด โดยทั่วไปจะมีอยู่ด้วยกัน 3 วิธี ดังนี้
- 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. You can get the installers from the [Golang Download Page](https://golang.org/dl/).
- 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.
- ติดตั้งจาก packages มาตรฐาน ที่ถูกปล่อยโดยตรง
- ทีมงานของ Go ได้เตรียมการติดตั้งที่สะดวกสบายบน Windows, Linux, Mac และระบบปฎิบัติการอื่นๆ ซึ่งนับเป็นวิธีเริ่มใช้งาน Go ที่สะดวกที่สุด
โดยสามารถดาวน์โหลดตัวติดตั้งจาก [หน้าดาวน์โหลดของ Golang](https://golang.org/dl/)
- ติดตั้งจาก source code ด้วยตัวเอง
- นับเป็นวิธีการติดตั้งที่ได้รับความนิยมในหมู่ของนักพัฒนาที่คุ้นเคยกับการทำงานบนระบบที่คล้ายกับ Unix
- ติดตั้งจากเครื่องมือประเภท third party ต่างๆ
- มีเครื่องมือประเภท third party และตัวจัดการ package อยู่มากมายที่สามารถใช้ในการติดตั้ง Go ยกตัวอย่างเช่น apt-get ใน Ubuntu และ homebrew ใน Mac
In case you want to install more than one version of Go on a computer, you should take a look at a tool called [GVM](https://github.com/moovweb/gvm). It is the best tool I've seen so far for accomplishing this task, otherwise you'd have to deal with it yourself.
ในกรณีที่ต้องการติดตั้ง Go มากกว่าหนึ่งเวอร์ชั่นในคอมพิวเตอร์เครื่องเดียว สามารถใช้เครื่องมือที่เรียกว่า [GVM](https://github.com/moovweb/gvm) นับเป็นเครื่องมือที่ดีที่สุดในการใช้งานแบบนี้เท่าที่เห็นมา ไม่อย่างนั้นแล้วเราก็ต้องลงมือทำทั้งหมดด้วยตัวเอง
## Install from source code
## ติดตั้งจาก source code
To compile Go 1.5 and upwards, you only need the previous version of Go, as Go has achieved bootstrapping. You only need Go to compile Go.
ในการคอมไพล์ Go ตั้งแต่เวอร์ชั่น 1.5 เป็นต้นมา เราเพียงแค่ต้องใช้ Go เวอร์ชั่นก่อนหน้าเท่านั้นในการคอมไพล์ Go
To compile Go 1.4 downwards, you will need a C compiler as some parts of Go are still written in Plan 9 C and AT&T assembler.
หากต้องการคอมไพล์ Go เวอร์ชั่นตั้งแต่ 1.4 ลงไป เราต้องใช้คอมไพล์เลอร์ภาษาซี เนื่องจากว่าบางส่วนของ Go ยังถูกเขียนด้วย Plan 9 C และ AT&T assembler อยู่
On a Mac, if you have installed Xcode, you already have the compiler.
บนระบบ Mac นั้น หากเราติดตั้ง Xcode อยู่แล้ว ก็สามารถใช้คอมไพล์ได้เลย
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:
ส่วนระบบที่ทำงานคล้าย Unix อื่นๆ ทั้งหลาย ต้องติดตั้ง gcc หรือคอมไพล์เลอร์ที่คล้ายกัน ยกตัวอย่างเช่น หากใช้ Ubuntu ก็สามารถใช้ตัวจัดการ package apt-get ซึ่งติดตั้งมากับ Ubuntu ด้วย เพื่อติดตั้งคอมไพล์เลอร์ที่เราต้องการ ดังนี้:
```sh
sudo apt-get install gcc libc6-dev
```
On Windows, you need to install MinGW in order to install gcc. Don't forget to configure your environment variables after the installation has completed.( ***Everything that looks like this means it's commented by a translator: If you are using 64-bit Windows, you should install the 64-bit version of MinGW*** )
At this point, execute the following commands to clone the Go source code and compile it.( ***It will clone the source code to your current directory. Switch your work path before you continue. This may take some time.*** )
โดยบน Windows นั้นจำเป็นต้องติดตั้ง MinGW ก่อนเพื่อที่จะติดตั้ง gcc และอย่าลืมตั้งค่า environment ของ Windows หลังจากที่ติดตั้งเสร็จเรียบร้อยแล้ว ( ***คอมเมนท์จากผู้แปล: หากใช้ Windows 64 bit ก็ควรเลือกติดตั้ง MinGW เวอร์ชั่น 64 bit ด้วยเหมือนกัน*** )
เมื่อถึงจุดนี้เราก็สามารถ clone source code ของ Go แล้วก็ทำการคอมไพล์ได้เลย ( ***ซอร์สโคดจะถูก clone ลงไปอยู่ในไดเร็คทอรีปัจจุบัน โดยการย้าย และการเปลี่ยนไดเร็คทอรีก่อนที่จะทำงานต่อ อาจจะใช้เวลาเล็กน้อย*** )
git clone https://go.googlesource.com/go
cd go/src
./all.bash
A successful installation will end with the message "ALL TESTS PASSED."
หากติดตั้งสำเร็จจะแสดงข้อความว่า "ALL TESTS PASSED."
On Windows, you can achieve the same by running `all.bat`.
บน Windows สามารถทำสิ่งเดียวกันนี้โดยใช้คำสั่ง `all.bat` แทน
If you are using Windows, the installation package will set your environment variables automatically. In Unix-like systems, you need to set these variables manually as follows. ( ***If your Go version is greater than 1.0, you don't have to set $GOBIN, and it will automatically be related to your $GOROOT/bin, which we will talk about in the next section***)
หากใช้ระบบปฎิบัติการ Windows ตัวติดตั้งจะทำการตั้งค่าตัวแปร environment ให้โดยอัตโนมัติ แต่่่หากเป็นระบบที่คล้าย Unix นั้น เราต้องตั้งค่าเหล่านั้นด้วยตัวเอง ดังนี้ ( ***หากเป็น Go เวอร์ชั่นที่มากกว่า 1.0 เราไม่จำเป็นต้องตั้งค่า $GOBIN โดยจะถูกตั้งค่าให้อย่างอัตโนมัติโดยอ้างอิงจาก $GOROOT/bin ซึ่งจะได้พูดถึงในบทถัดไป*** )
export GOROOT=$HOME/go
export GOBIN=$GOROOT/bin
export PATH=$PATH:$GOROOT/bin
If you see the following information on your screen, you're all set.
หากเราเห็นข้อความด้านล่างนี้ปรากฎบนหน้าจอ แสดงว่าทุกอย่างพร้อมใช้งานแล้ว
![](images/1.1.mac.png?raw=true)
Figure 1.1 Information after installing from source code
รูป 1.1 ข้อมูลที่แสดงภายหลังการติดตั้งด้วย source code
Once you see the usage information of Go, it means you have successfully installed Go on your computer. If it says "no such command", check that your $PATH environment variable contains the installation path of Go.
เมื่อหน้าจอแสดงคำแนะนำในการใช้งานของ Go นั่นแสดงว่าการติดตั้งสำเร็จแล้ว แต่หากมีข้อความว่า "no such command" ให้ทำการตรวจดูค่า $PATH ในตัวแปร environment ของระบบ มี path ที่ติดตั้ง Go อยู่หรือไม่
## Using the standard installation packages
## ติดตั้งจาก packages มาตรฐาน
Go has one-click installation packages for every supported operating system. 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.
Go นั้นมีตัวติดตั้ง package มาตรฐานในแทบจะทุกระบบปฎิบัติการ โดย package จะติดตั้ง Go ลงไปที่ `/usr/local/go` (`c:\Go` สำหรับ Windows) หากไม่ได้เลือกเป็นอย่างอื่น ซึ่งแน่นอนว่าเราสามารถเลือกได้เองว่าจะติดตั้งไว้ที่ใด แต่เราก็ต้องแก้ไขตัวแปร environment ทั้งหมดด้วยตัวเองดังที่ได้แสดงไว้ด้านบน
### How to check if your operating system is 32-bit or 64-bit?
### จะรู้ได้อย่างไรว่าระบบปฎิบัติการเป็นแบบ 32 bit หรือ 64 bit?
Our next step depends on your operating system type, so we have to check it before we download the standard installation packages.
ขั้นต่อไปนั้นขึ้นอยู่กับว่าเราใช้ระบบปฎิบัติการชนิดใด ดังนั้นเราจึงจำเป็นต้องตาวจสอบให้มั่นใจก่อนที่จะดาวน์โหลดตัวติดตั้ง package ลงมา
If you are using Windows, press `Win+R` and then run the command tool. Type the `systeminfo` command and it will show you some useful system information. Find the line that says "system type" -if you see "x64-based PC" that means your operating system is 64-bit, 32-bit otherwise.
หากใช้ Windows ให้กด `Win+R` แล้วสั่งรัน command tool แล้วพิมพ์คำสั่ง `systeminfo` จะเป็นการแสดงข้อมูลเกี่ยวกับระบบออกมา มองหาบรรทัดที่มีข้อความว่า "system type" หากเห็นว่าเป็น "x64-based PC" แสดงว่าระบบปฎิบัติการเป็นแบบ 64 bit นอกเหนือจากนี้แสดงว่าเป็น 32 bit
I strongly recommend downloading the 64-bit package if you are a Mac user, as Go no longer supports pure 32-bit processors on Mac OSX.
ขอแนะนำให้ดาวน์โหลด package เวอร์ชั่น 64 bit สำหรับคนที่ใช้ Mac เนื่องจากว่า Go ไม่ได้ซัพพอร์ทหน่วยประมวลผลแบบ 32 bit บน Mac OSX แล้ว
Linux users can type `uname -a` in the terminal to see system information.
A 64-bit operating system will show the following:
สำหรับผู้ใช้งาน Linux สามารถใช้คำสั่ง `uname -a` ใน terminal เพื่อดูข้อมูลของระบบ หากเป็นระบบปฎิัติการแบบ 64 bit จะแสดงข้อความดังนี้:
<some description> x86_64 x86_64 x86_64 GNU/Linux
// some machines such as Ubuntu 10.04 will show as following
x86_64 GNU/Linux
32-bit operating systems instead show:
หากเป็นระบบปฎิบัติการแบบ 32 bit จะแสดงข้อความนี้แทน:
<some description> i686 i686 i386 GNU/Linux
### Mac
Go to the [download page](https://golang.org/dl/), choose `go1.4.2.darwin-386.pkg` (The later version has no 32-bit download.)for 32-bit systems and `go1.8.3.darwin-amd64.pkg` for 64-bit systems. Going all the way to the end by clicking "next", `~/go/bin` will be added to your system's $PATH after you finish the installation. Now open the terminal and type `go`. You should see the same output shown in figure 1.1.
ไปที่ [หน้าดาวน์โหลด](https://golang.org/dl/) แล้วเลือก `go1.4.2.darwin-386.pkg` (เวอร์ชั่นหลังนี้จะไม่มีแบบ 32 bit ให้ดาวน์โหลดแล้ว) หากใช้ระบบ 32 bit หรือเลือก `go1.8.3.darwin-amd64.pkg` หากใช้ระบบ 64 bit ติดตั้งตามขั้นตอนโดยการกดปุ่ม "next" ซึ่ง `~/go/bin` จะถูกเพิ่มเข้าไปในตัวแปร $PATH ของระบบหลังจากการติดตั้งสำเร็จ หลังจากนั้นให้เปิด terminal แล้วพิมพ์คำสั่ง `go` ควรมีข้อความแสดงขึ้นมาเหมือนในภาพ 1.1
### Linux
Go to the [download page](https://golang.org/dl/), choose `go1.8.3.linux-386.tar.gz` for 32-bit systems and `go1.8.3.linux-amd64.tar.gz` for 64-bit systems. Suppose you want to install Go in the `$GO_INSTALL_DIR` path. Uncompress the `tar.gz` to your chosen path using the command `tar zxvf go1.8.3.linux-amd64.tar.gz -C $GO_INSTALL_DIR`. Then set your $PATH with the following: `export PATH=$PATH:$GO_INSTALL_DIR/go/bin`. Now just open the terminal and type `go`. You should now see the same output displayed in figure 1.1.
ไปที่ [หน้าดาวน์โหลด](https://golang.org/dl/) แล้วเลือก `go1.8.3.linux-386.tar.gz` สำหรับระบบแบบ 32 bit หรือเลือก `go1.8.3.linux-amd64.tar.gz` สำหรับระบบแบบ 64 bit แล้วทำการแตก `tar.gz` ลงไปที่ path ที่เราต้องการติดตั้งโดยใช้คำสั่ง `tar zxvf go1.8.3.linux-amd64.tar.gz -C $GO_INSTALL_DIR` โดยแทนค่า `GO_INSTALL_DIR` ด้วย path ที่เราต้องการ เมื่อเสร็จแล้วจึงทำการตั้งค่า $PATH ด้วยคำสั่ง `export PATH=$PATH:$GO_INSTALL_DIR/go/bin` เสร็จแล้วสามารถเปิด terminal และพิมพ์คำสั่ง `go` ควรมีข้อความแสดงขึ้นมาเหมือนในภาพ 1.1
### Windows
Go to the [download page](https://golang.org/dl/), choose `go1.8.3.windows-386.msi` for 32-bit systems and `go1.8.3.windows-amd64.msi` for 64-bit systems. Going all the way to the end by clicking "next", `c:/go/bin` will be added to `path`. Now just open a command line window and type `go`. You should now see the same output displayed in figure 1.1.
ไปที่ [หน้าดาวน์โหลด](https://golang.org/dl/) แล้วเลือก `go1.4.2.windows-386.msi` หากใช้ระบบ 32 bit หรือเลือก `go1.8.3.windows-amd64.msi` หากใช้ระบบ 64 bit ติดตั้งตามขั้นตอนโดยการกดปุ่ม "next" ซึ่ง `c:/go/bin` จะถูกเพิ่มเข้าไปในตัวแปร `path` ของระบบหลังจากการติดตั้งสำเร็จ หลังจากนั้นให้เปิดหน้าต่าง command line แล้วพิมพ์คำสั่ง `go` ควรมีข้อความแสดงขึ้นมาเหมือนในภาพ 1.1
## Use third-party tools
## ติดตั้งจากเครื่องมือประเภท third-party
### 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:
GVM เป็นเครื่องมือที่ใช้ควบคุมเวอร์ชั่นของ Go หากติดตั้งมากกว่าหนึ่งเวอร์ชั่น ที่พัฒนาโดย third party ซึ่งคล้ายกับ rvm ของภาษา ruby นั่นเอง โดยใช้งานได้ค่อนข้างง่าย และสามารถทำการติดตั้ง gvm โดยพิมพ์คำสั่งใน terminal ดังนี้:
bash < <(curl -s -S -L https://raw.github.com/moovweb/gvm/master/binscripts/gvm-installer)
Then we install Go using the following commands:
เมื่อเสร็จแล้วจะสามารถติดตั้ง Go โดยใช้คำสั่งดังนี้:
gvm install go1.8.3
gvm use go1.8.3
After the process has finished, you're all set.
หลังจากเสร็จแล้ว ก็พร้อมสำหรับการใช้งานได้ทันที
### 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.
Ubuntu เป็นระบบปฎิบัติการ Linux ที่ได้รับความนิยมอย่างแพร่หลาย โดยจะมาพร้อมกับเครื่องมือในการจัดการ package ที่ชื่อว่า `apt-get` และเราสามารถที่จะติดตั้ง Go โดยใช้คำสั่งดังนี้:
sudo add-apt-repository ppa:gophers/go
sudo apt-get update
@@ -144,5 +142,5 @@ Homebrew is a software management tool commonly used in Mac to manage packages.
## Links
- [Directory](preface.md)
- Previous section: [Go environment configuration](01.0.md)
- Next section: [$GOPATH and workspace](01.2.md)
- บทก่อนหน้า: [การตั้งค่าสภาพแวดล้อมของ Go](01.0.md)
- บทถัดไป: [$GOPATH และ workspace](01.2.md)

View File

@@ -1,5 +1,5 @@
- 1.[การตั้งค่าสภาพแวดล้อมของ Go](01.0.md)
- 1.1. [Installation](01.1.md)
- 1.1. [การติดตั้ง](01.1.md)
- 1.2. [$GOPATH and workspace](01.2.md)
- 1.3. [Go commands](01.3.md)
- 1.4. [Go development tools](01.4.md)