-
Notifications
You must be signed in to change notification settings - Fork 6
03. Go개발환경 구축_Mac 편
참고사이트: http://www.cyberciti.biz/faq/installing-go-programming-language-on-mac-os-x/
Go페북 그룹의 Donghyun Cho 님께서 참고하여 작성해주셨습니다.
##Step 1. Go 언어의 사용을 위해서 gcc가 필요합니다.
a. 터미널에서 gcc를 입력하고 엔터를 치면 gcc설치를 위한 팝업 메세지가 나옵니다.
$ gcc
b. Install(설치) 버튼을 눌러 설치하세요.
c. Xcode가 이미 설치되어 있나요?
i. Xcode 설치 확인을 위해 다음 명령문을 실행합니다.
$ xcode-select -p
ii. 이미 설치가 되어있으면 다음과 같은 결과를 볼 수 있습니다.
/Applications/Xcode.app/Contents/Developer
iii. 설치가 되어있으면 다음 명령문으로도 gcc를 설치할 수 있습니다.
$ xcode-select --install
a. Go를 사용하기 위해선 Xcode와 함께 설치되는 gcc가 필요합니다. 먼저 Xcode를 설치하세요.
b. gcc/LLVM 컴파일러 설치 i. Xcode의 설치가 완료되면, Xcode를 실행하고 그림과 같이 다음 메뉴로 이동하세요.
Xcode menu > Preferences > Downloads
ii. Command Line Tools의 Install(설치) 버튼을 눌러 설치합니다.
a. 설치 확인을 위해 다음 명령문을 실행합니다.
$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix
-
다운로드 페이지(https://golang.org/dl/) 로 가서 최신 버전의 패키지를 다운로드합니다.
-
저는 여기서 OSX 64 bit용 go1.4.2.darwin-amd64-osx10.8.pkg 선택해보겠습니다.
-
다운로드가 완료되면 파일을 열어서 설치를 시작합니다.
- 설치가 제대로 되었는지 확인합니다. a. 터미널에서 다음 명령문을 실행합니다.
$ ls -l /usr/local/go
b.출력된 예제
total 136
-rw-r--r-- 1 root wheel 17575 Feb 17 23:42 AUTHORS
-rw-r--r-- 1 root wheel 24564 Feb 17 23:42 CONTRIBUTORS
-rw-r--r-- 1 root wheel 1479 Feb 17 23:42 LICENSE
-rw-r--r-- 1 root wheel 1303 Feb 17 23:42 PATENTS
-rw-r--r-- 1 root wheel 1112 Feb 17 23:42 README
-rw-r--r-- 1 root wheel 7 Feb 17 23:45 VERSION
drwxr-xr-x 10 root wheel 340 Feb 17 23:42 api
drwxr-xr-x 5 root wheel 170 Feb 17 23:44 bin
drwxr-xr-x 4 root wheel 136 Feb 17 23:44 blog
drwxr-xr-x 39 root wheel 1326 Feb 17 23:42 doc
-rw-r--r-- 1 root wheel 1150 Feb 17 23:42 favicon.ico
drwxr-xr-x 11 root wheel 374 Feb 17 23:42 include
drwxr-xr-x 3 root wheel 102 Feb 17 23:42 lib
drwxr-xr-x 15 root wheel 510 Feb 17 23:45 misc
drwxr-xr-x 6 root wheel 204 Feb 17 23:43 pkg
-rw-r--r-- 1 root wheel 26 Feb 17 23:42 robots.txt
drwxr-xr-x 64 root wheel 2176 Feb 17 23:42 src
drwxr-xr-x 215 root wheel 7310 Feb 17 23:42 test
- 터미널에서 go의 실행을 위해 환경변수를 등록합니다. a. 여러가지 방법이 있겠지만 저는 ~/.bash_profile을 수정하여 사용하도록 하겠습니다. i. vim이나 pico와 같은 에디터를 사용하여 가장 마지막줄에 다음 문장을 추가하고 저장합니다.
export PATH=$PATH:/usr/local/go/bin
ii. 수정한 문장의 적용을 위해 다음 명령문을 실행합니다.
$ source ~/.bash_profile 또는 $ . ~/.bash_profile
- Go를 실행해봅니다.
$ go 또는 $ go env
hello.go라는 문서파일을 생성합니다.
$ vi hello.go
다음과 같이 작성해주세요.
/* hello.go - My first Golang program */
package main
import "fmt"
func main() {
fmt.Printf("Hello, world\n")
}
자 이제 실행해봅시다.
$ go run hello.go
Hello, world