1. 소개

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