Created
July 18, 2023 07:06
-
-
Save zscole/a8a4bef6ee2ee571b40b817efb50b530 to your computer and use it in GitHub Desktop.
sets up go on mac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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