갈루아의 반서재

설치 파일 다운로드 

하단 링크에서 운영체제에 맞는 설치 파일을 다운로드한다. 본 포스팅에서는 리눅스 기반으로 진행한다. 

https://golang.org/dl/

파일을 다운로드한 후 다음과 같이 /usr/local/go 디렉토리를 만들어 압축을 해제한다 (일반적으로 root 계정이나 sudo 를 통해 진행해야 한다).

1
# tar -C /usr/local -xzf go1.10.3.linux-amd64.tar.gz
cs

/etc/profile (system-wide 인 경우) 또는 $HOME/.profile 파일을 열어 /usr/local/go/bin 을 PATH 환경변수에 추가한다. 

1
2
3
4
5
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
 
export PATH=$PATH:/usr/local/go/bin
 
cs

변경된 내용을 source $HOME/.profile 등을 통해 즉시 반영하거나 로그오프 후 새로 로그인해도 된다.


설치 테스트

작업공간을 셋팅하고, 다음과 같이 간단한 프로그램을 만들어서 정상적으로 Go 가 설치되었는지 확인해보자. $HOME/go 에 작업공간 디렉토리를 만든다. 물론 다른 디렉토리를 사용할 수도 있다. 이 경우 GOPATH 환경변수를 설정해야 한다. 

다음으로 src/hello 디렉토리를 작업공간안에 만들고, 그 디렉토리안에 다음과 같은 hello.go 파일을 만들자.

1
2
3
4
5
6
7
package main
 
import "fmt"
 
func main() {
    fmt.Printf("hello, world\n")
}
cs

go tool 을 이용하여 빌드하자. 빌드를 하게되면 아래에서 보듯이 실행가능한 hello 라는 파일이 생성된다. 해당 파일을 실행시켜 "hello, world" 메시지가 출력되었다면 Go가 정상적으로 설치된 것이다. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
~# cd $HOME/go/src/hello
~/go/src/hello# ls -al
total 8
drwxr-xr-2 root root 4096 Aug 24 16:52 .
drwxr-xr-3 root root 4096 Aug 24 16:52 ..
-rw-r--r-- 1 root root    0 Aug 24 16:50 hello.go
 
~/go/src/hello# go build
~/go/src/hello# ls -al
total 1988
drwxr-xr-2 root root    4096 Aug 24 17:07 .
drwxr-xr-3 root root    4096 Aug 24 16:52 ..
-rwxr-xr-1 root root 2020012 Aug 24 17:07 hello
-rw-r--r-- 1 root root      79 Aug 24 17:07 hello.go
 
~/go/src/hello# ./hello
hello, world
 
cs

작업공간의 bin 디렉토리에 바이너리를 설치하려면 go install 을 사용하면 되고, 삭제할려면 go clean -i 명령을 사용하면 된다.