1. 소개
Go 언어는 많은 글로벌 기업들이 효율성, 단순성, 빠른 런타임 속도를 이유로 선호하고 있다.
이 글을 통해 Linux 서버에 Go 언어 환경을 설치하는 방법을 공유한다.
2. 설치
2-1. 다운로드
$ wget https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz
2-2. 압축해제
$ tar -xvzf go1.10.3.linux-amd64.tar.gz
그러면 go 라는 이름의 폴더에 압축이 풀린다.
3. 실행
나는 편의상 go 폴더를 다른 곳으로 옮겼다. 그리고 PATH를 설정했다.
$ mv go /lang $ export PATH=$PATH:/lang/go/bin
실행!
$ go Go is a tool for managing Go source code. Usage: go command [arguments] The commands are: build compile packages and dependencies clean remove object files and cached files doc show documentation for package or symbol env print Go environment information bug start a bug report fix update packages to use new APIs fmt gofmt (reformat) package sources generate generate Go files by processing source get download and install packages and dependencies install compile and install packages and dependencies list list packages run compile and run Go program test test packages tool run specified go tool version print Go version vet report likely mistakes in packages Use "go help [command]" for more information about a command. Additional help topics: c calling between Go and C buildmode build modes cache build and test caching filetype file types gopath GOPATH environment variable environment environment variables importpath import path syntax packages package lists testflag testing flags testfunc testing functions Use "go help [topic]" for more information about that topic.
버전 확인 방법이다.
$ go version go version go1.10.3 linux/amd64
4. 테스트 코드
간략한 테스트 코드를 만들어 실행했다.
package main import "fmt" func main() { fmt.Println("Welcome to Starbucks"); }
실행 결과 :
$ go run starbucks.go Welcome to Starbucks
5. 패키지 설치
yum으로도 설치할 수 있다.
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd 204 packages excluded due to repository priority protections Resolving Dependencies --> Running transaction check ---> Package golang.x86_64 0:1.9.4-1.amzn2.0.2 will be installed --> Processing Dependency: golang-src = 1.9.4-1.amzn2.0.2 for package: golang-1.9.4-1.amzn2.0.2.x86_64 --> Processing Dependency: golang-bin = 1.9.4-1.amzn2.0.2 for package: golang-1.9.4-1.amzn2.0.2.x86_64 --> Running transaction check ---> Package golang-bin.x86_64 0:1.9.4-1.amzn2.0.2 will be installed ---> Package golang-src.noarch 0:1.9.4-1.amzn2.0.2 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: golang x86_64 1.9.4-1.amzn2.0.2 amzn2-core 611 k Installing for dependencies: golang-bin x86_64 1.9.4-1.amzn2.0.2 amzn2-core 48 M golang-src noarch 1.9.4-1.amzn2.0.2 amzn2-core 5.1 M Transaction Summary ================================================================================ Install 1 Package (+2 Dependent packages) Total download size: 54 M Installed size: 221 M Is this ok [y/d/N]: y Downloading packages: (1/3): golang-1.9.4-1.amzn2.0.2.x86_64.rpm | 611 kB 00:00 (2/3): golang-src-1.9.4-1.amzn2.0.2.noarch.rpm | 5.1 MB 00:00 (3/3): golang-bin-1.9.4-1.amzn2.0.2.x86_64.rpm | 48 MB 00:01 -------------------------------------------------------------------------------- Total 50 MB/s | 54 MB 00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : golang-src-1.9.4-1.amzn2.0.2.noarch 1/3 Installing : golang-bin-1.9.4-1.amzn2.0.2.x86_64 2/3 Installing : golang-1.9.4-1.amzn2.0.2.x86_64 3/3 Verifying : golang-src-1.9.4-1.amzn2.0.2.noarch 1/3 Verifying : golang-1.9.4-1.amzn2.0.2.x86_64 2/3 Verifying : golang-bin-1.9.4-1.amzn2.0.2.x86_64 3/3 Installed: golang.x86_64 0:1.9.4-1.amzn2.0.2 Dependency Installed: golang-bin.x86_64 0:1.9.4-1.amzn2.0.2 golang-src.noarch 0:1.9.4-1.amzn2.0.2 Complete!