How to install golang to Ubuntu 20.04

Download

wget -c https://golang.org/dl/go1.16.4.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local

Or

sudo tar -C /usr/local/ -xzf go1.16.4.linux-amd64.tar.gz

Configuration

Add the go_path variable to the configuration file

sudo tee /etc/profile.d/go.sh <<-'EOF'
export GOROOT=/usr/local/go
export GOPATH=~/Public/project/default
export PATH=$PATH:$GOROOT/bin:$GOPATH
EOF

Enable the ability to automatically append GOPATH at boot

tee -a ~/.bashrc <<-'EOF'
if [ -f /etc/profile.d/go.sh ]; then
    . /etc/profile.d/go.sh
fi
EOF

Make environment variables take effect

source .bashrc

Verification

Verification results

lwk@qwfys:~$ echo $GOPATH
/home/lwk/Public/project/default
lwk@qwfys:~$ echo $GOROOT
/usr/local/go
lwk@qwfys:~$ go version
go version go1.16.4 linux/amd64
lwk@qwfys:~$
上一篇:how to solve gpg key error for archlinuxcn


下一篇:研究生学术英语写作网课答案