Skip to content

Instantly share code, notes, and snippets.

@zscole
Created July 18, 2023 07:06
Show Gist options
  • Select an option

  • Save zscole/a8a4bef6ee2ee571b40b817efb50b530 to your computer and use it in GitHub Desktop.

Select an option

Save zscole/a8a4bef6ee2ee571b40b817efb50b530 to your computer and use it in GitHub Desktop.
sets up go on mac
#!/bin/bash
# Check if Go is already installed
if go version &> /dev/null
then
echo "Go is already installed. Exiting."
exit 0
fi
# Set the version of Go to install
GO_VERSION="1.20.6" # replace this with the version you want
# Download and install Go
curl -O https://dl.google.com/go/go${GO_VERSION}.darwin-amd64.pkg
sudo installer -pkg go${GO_VERSION}.darwin-amd64.pkg -target /
# Set up the Go workspace
echo "Creating Go workspace directories at $HOME/go"
mkdir -p $HOME/go/{src,pkg,bin}
# Add GOPATH and Go bin directory to the PATH
echo "Adding GOPATH and Go bin directory to PATH in .bash_profile and .zshrc"
echo "export GOPATH=$HOME/go" >> ~/.bash_profile
echo "export PATH=\$PATH:\$GOPATH/bin:/usr/local/go/bin" >> ~/.bash_profile
echo "export GOPATH=$HOME/go" >> ~/.zshrc
echo "export PATH=\$PATH:\$GOPATH/bin:/usr/local/go/bin" >> ~/.zshrc
# Apply the new settings
source ~/.bash_profile
source ~/.zshrc
# Check the Go version
echo "Go version $(go version) has been installed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment