이번 시간에는 리눅스에서 Go를 설치해보도록 하겠습니다.
리눅스 버전 Go 설치
Downloads - The Go Programming Language
Downloads After downloading a binary release suitable for your system, please follow the installation instructions. If you are building from source, follow the source installation instructions. See the release history for more information about Go releases
go.dev
해당 사이트로가 Linux 최신버전을 확인해줍니다.
root@localhost:~# GO_VERSION=1.19.4
root@localhost:~# curl -LO https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz
root@localhost:~# rm -rf /usr/local/go && tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz
root@localhost:~# cat ~/.profile | grep /usr/local/go/bin || echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile
root@localhost:~# cat ~/.profile | grep GOPATH= || echo 'export GOPATH=$(go env GOPATH)' >> ~/.profile
root@localhost:~# cat ~/.profile | grep GOPATH/bin || echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.profile
root@localhost:~# source ~/.profile
root@localhost:~# echo $GOPATH
root@localhost:~# go version
go version go1.19.4 linux/amd64
그다음 리눅스 디렉토리에 폴더하나를 생성해서
프로젝트 코드를 넣고 출력해보겠습니다.
// hello-world.go
package main
import "fmt"
func main() {
fmt.Print("hello world")
}
// 코드 입력후
koras02@jung-desktop ~/study/go/go-blog go run hello-world.go
hello world%
코드를 넣고 난 뒤에는 cmd 창에서
go 명령어를 통해서 해당 파일을
실행해줍니다.
koras02@jung-desktop ~/study/go/go-blog go build hello-world.go
koras02@jung-desktop ~/study/go/go-blog ./hello-world
hello world%
go build를 이용해서 빌드로 디렉토리를 생성 후
그 안에 실행 파일을 생성해줍니다.
그후 명령어로 결과물을 출력할 수 있습니다.
참고 문서
Go Println() - 제타위키
다음 문자열 포함...
zetawiki.com
Go 언어 웹 프로그래밍 철저 입문: 1.4.1 코드 실행
더북(TheBook): (주)도서출판 길벗에서 제공하는 IT 도서 열람 서비스입니다.
thebook.io
GitHub - Koras02/go-tutorial-blog: https://koras02.tistory.com/category/%ED%94%84%EB%A1%A0%ED%8A%B8%20%EC%97%94%EB%93%9C/Go
https://koras02.tistory.com/category/%ED%94%84%EB%A1%A0%ED%8A%B8%20%EC%97%94%EB%93%9C/Go - GitHub - Koras02/go-tutorial-blog: https://koras02.tistory.com/category/%ED%94%84%EB%A1%A0%ED%8A%B8%20%EC%...
github.com
'프론트 엔드 > Go' 카테고리의 다른 글
[Go] Go 코드 분석기와 웹페이지 띄우기, 기본 문법 - 반복문 (0) | 2023.01.09 |
---|---|
[Go] GO를 이용해 HTTP Server 만들기 (0) | 2022.03.03 |
[Go] Go 언어 프로그래밍 입문 - Go는 어떤언어 인가? (0) | 2022.02.25 |