티스토리 뷰
Programming Languages/GoLang
[Go언어] Ubuntu20.04에 GoLang 설치하기 (1.17 ver), 환경변수 영구 등록
헐리 2022. 1. 18. 10:42APT-GET
# apt 패키지 업데이트
sudo apt-get update
sudo apt-get -y upgrade
# wget 설치
sudo apt-get install wget
1.17버전 다운로드
wget https://golang.org/dl/go1.17.linux-amd64.tar.gz
최신버전이나 특정 버전이 설치하고 싶다면 아래의 링크에서 확인할 수 있다
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
위에서 다운로드 한 tar파일 압축해제
tar -xvf go1.17.linux-amd64.tar.gz
환경변수 설정
centos7의 경우 vim ~/.bashrc
ubuntu20의 경우 vim $HOME/.profile
sudo vi $HOME/.profile
# GOROOT: 설치된 Go 패키지의 경로
export GOROOT=$HOME/go
# GOPATH: Go 패키지를 이용해 작업할 공간
export GOPATH =/project/gogo
# 동일
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
이처럼 환경변수 설정을 해야하는데 터미널청에서 그냥 export만 해버리면 환경변수가 영구적으로 등록되지 않는다
방법은
vim ~/.bashrc
이 파일의 맨 밑줄에 위의 환경변수를 등록한 후
. ./.profile
를 해주고
echo $GOROOT
이렇게 테스트 하면 완료