본문 바로가기

OS/Linux

[Linux] Ubuntu 20.04 에서 Go 최신 버전 설치

기존 설치 버전 삭제

root@razor1911-Virtual-Machine:/home/razor1911/AdGuardHome# sudo apt remove --autoremove golang
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  gccgo-9 golang golang-1.13 golang-1.13-doc golang-1.13-go golang-1.13-race-detector-runtime golang-1.13-src golang-doc
  golang-go golang-race-detector-runtime golang-src libgo-9-dev libgo14
0 upgraded, 0 newly installed, 13 to remove and 7 not upgraded.
After this operation, 520 MB disk space will be freed.
Do you want to continue? [Y/n]

 

다음 URL 에서 최신 go 설치본 URL 확인

https://golang.org/dl/

 

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

golang.org

 

다운로드

root@razor1911-Virtual-Machine:/home/razor1911# wget https://golang.org/dl/go1.17.2.linux-amd64.tar.gz
--2021-11-04 10:20:02--  https://golang.org/dl/go1.17.2.linux-amd64.tar.gz
Resolving golang.org (golang.org)... 34.64.4.49, 2404:f340:10:1801::2011
Connecting to golang.org (golang.org)|34.64.4.49|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://dl.google.com/go/go1.17.2.linux-amd64.tar.gz [following]
--2021-11-04 10:20:03--  https://dl.google.com/go/go1.17.2.linux-amd64.tar.gz
Resolving dl.google.com (dl.google.com)... 216.58.220.110, 2404:6800:4004:808::200e
Connecting to dl.google.com (dl.google.com)|216.58.220.110|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 134803982 (129M) [application/x-gzip]
Saving to: ‘go1.17.2.linux-amd64.tar.gz’

go1.17.2.linux-amd64.tar.gz    100%[===================================================>] 128.56M  46.5MB/s    in 2.8s

2021-11-04 10:20:06 (46.5 MB/s) - ‘go1.17.2.linux-amd64.tar.gz’ saved [134803982/134803982]

root@razor1911-Virtual-Machine:/home/razor1911#

 

압축 해제 및 디렉토리 이동

root@razor1911-Virtual-Machine:/home/razor1911# sudo tar -xvf go1.17.2.linux-amd64.tar.gz
root@razor1911-Virtual-Machine:/home/razor1911# sudo mv go /usr/local

 

패스 설정 

root@razor1911-Virtual-Machine:/home/razor1911# sudo mv go /usr/local
root@razor1911-Virtual-Machine:/home/razor1911# export GOROOT=/usr/local/go
root@razor1911-Virtual-Machine:/home/razor1911# export GOPATH=$HOME/Projects/Proj1
root@razor1911-Virtual-Machine:/home/razor1911# export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
root@razor1911-Virtual-Machine:/home/razor1911# go version
go version go1.17.2 linux/amd64

 

빌드 

go build