Skip to content

Instantly share code, notes, and snippets.

@crazytaxii
Last active June 6, 2021 14:01
Show Gist options
  • Save crazytaxii/1bbb809bbb6d8110cb7fb699bf687059 to your computer and use it in GitHub Desktop.
Save crazytaxii/1bbb809bbb6d8110cb7fb699bf687059 to your computer and use it in GitHub Desktop.
Setting up a Golang development environment quickly!
#!/bin/bash
set -e
install_docker() {
sudo yum install yum-utils -y
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io -y
sudo systemctl is-active --quiet docker || sudo systemctl start docker
sudo systemctl is-enabled --quiet docker || sudo systemctl enable docker
}
install_dev_tools() {
sudo yum install wget vim git tree -y
sudo yum group install "Development tools" -y
}
install_go() {
go_ver="1.16.4" # default go 1.16.4
if [ -n $1 ]; then
go_ver=$1
fi
wget https://golang.org/dl/go$go_ver.linux-amd64.tar.gz -P /tmp/
sudo tar -C /usr/local -xzf /tmp/go$go_ver.linux-amd64.tar.gz
mkdir -p $HOME/go/src $HOME/go/bin $HOME/go/pkg
echo "export GOPATH=\$HOME/go" >> $HOME/.bashrc
echo "export GOBIN=\$GOPATH/bin" >> $HOME/.bashrc
echo "export PATH=\$PATH:/usr/local/go/bin:\$GOBIN" >> $HOME/.bashrc
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:/usr/local/go/bin:$GOBIN
go version
rm -rf /tmp/go$go_ver.linux-amd64.tar.gz
}
main() {
if [[ $(systemctl cat firewalld.service > /dev/null 2>&1) -eq 0 ]]; then
sudo systemctl is-active --quiet firewalld && sudo systemctl stop firewalld
sudo systemctl is-enabled --quiet firewalld && sudo systemctl disable firewalld
fi
sudo yum update -y
install_dev_tools
install_docker
install_go $1
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment