"리눅스 Go 설치"의 두 판 사이의 차이

 
(같은 사용자의 중간 판 24개는 보이지 않습니다)
1번째 줄: 1번째 줄:
{{다른뜻|우분투 go 1.6 설치}}
{{테스트|Ubuntu 16, CentOS 7}}
{{테스트|Ubuntu 16, CentOS 7}}
==다운로드==
==개요==
;리눅스 Go 설치
* https://golang.org/dl/ 접속하여 최신버전 확인
* https://golang.org/dl/ 접속하여 최신버전 확인


==설치==
==설치==
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
GOLANG_VERSION=1.16.3
GO_VERSION=1.22.0
 
curl -LO https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz
curl -LO https://dl.google.com/go/go${GOLANG_VERSION}.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz
tar -C /usr/local -xzf go${GOLANG_VERSION}.linux-amd64.tar.gz
grep /usr/local/go/bin $HOME/.profile || echo 'export PATH=$PATH:/usr/local/go/bin' >> $HOME/.profile
export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:/usr/local/go/bin
 
go version
echo 'export GOPATH=$HOME/go' >> ~/.bash_profile
sed '$!N; /^\(export GOPATH=.*\)\n\1$/!P; D' -i ~/.bash_profile
source ~/.bash_profile
</syntaxhighlight>
</syntaxhighlight>


==테스트==
==실습==
<syntaxhighlight lang='console'>
<syntaxhighlight lang='console'>
user01@localhost:~$ go version
root@localhost:~# GO_VERSION=1.19.4
go version go1.16.3 linux/amd64
root@localhost:~# curl -LO https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz
  % Total    % Received % Xferd  Average Speed  Time    Time    Time  Current
                                Dload  Upload  Total  Spent    Left  Speed
100  142M  100  142M    0    0  5290k      0  0:00:27  0:00:27 --:--:-- 5915k
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='console'>
mkdir -p ~/go/src
root@localhost:~# rm -rf /usr/local/go && tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz
cd ~/go/src/
root@localhost:~# cat ~/.profile | grep /usr/local/go/bin || echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile
echo 'package main;import "fmt";func main(){ fmt.Println("hello world")}' > hello.go
root@localhost:~# cat ~/.profile | grep GOPATH= || echo 'export GOPATH=$(go env GOPATH)' >> ~/.profile
go run hello.go
root@localhost:~# cat ~/.profile | grep GOPATH/bin || echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.profile
go build hello.go
root@localhost:~# source ~/.profile
./hello
root@localhost:~# echo $GOPATH
/root/go
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='console'>
<syntaxhighlight lang='console'>
user01@localhost:~$ mkdir -p ~/go/src
root@localhost:~# go version
user01@localhost:~$ cd ~/go/src/
go version go1.19.4 linux/amd64
user01@localhost:~/go/src$ echo 'package main;import "fmt";func main(){ fmt.Println("hello world")}' > hello.go
user01@localhost:~/go/src$ go run hello.go
hello world
user01@localhost:~/go/src$ go build hello.go
user01@localhost:~/go/src$ ./hello
hello world
</syntaxhighlight>
</syntaxhighlight>


==같이 보기==
==같이 보기==
* [[우분투 go 1.6 설치]]
* [[윈도우 go 설치]]
* [[리눅스 Go 업그레이드]]
* [[Go 헬로우 월드 빌드·실행]]


==참고==
==참고==

2024년 2월 18일 (일) 02:12 기준 최신판

1 개요[ | ]

리눅스 Go 설치

2 설치[ | ]

GO_VERSION=1.22.0
curl -LO https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz
grep /usr/local/go/bin $HOME/.profile || echo 'export PATH=$PATH:/usr/local/go/bin' >> $HOME/.profile
export PATH=$PATH:/usr/local/go/bin
go version

3 실습[ | ]

root@localhost:~# GO_VERSION=1.19.4
root@localhost:~# curl -LO https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  142M  100  142M    0     0  5290k      0  0:00:27  0:00:27 --:--:-- 5915k
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/go
root@localhost:~# go version
go version go1.19.4 linux/amd64

4 같이 보기[ | ]

5 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}