Choose the right version
Install
- Install the specified version through brew, and the installation fails. If you need to install the corresponding version, you can download the corresponding installation package from the official website.
brew install go
- successfully installed
Configure multiple versions
- Download different versions from the official website
- Extract to any directory
ex: /usr/local/go1.17
- Modify environment variables
open -e .bash_profile
- Add the following at the end of the .bash_profile file
export GOROOT=/usr/local/go1.17 # 下载的 Go 版本路径
export GOPATH=$HOME/go
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH
- make it effective
source .bash_profile
- Successful installation
- Use alias configuration to quickly switch versions, very easy to use
alias go113="export GOROOT=/usr/local/go1.13.1; export PATH=$GOROOT/bin:$PATH; go version"
alias go114="export GOROOT=/usr/local/go1.14.1; export PATH=$GOROOT/bin:$PATH; go version"
uninstall
- Remove Go binaries
sudo rm -rf /usr/local/go
- delete GOPATH path
sudo nano /etc/paths
This opens a text editor in Terminal with your system path. If you use GOPATH path, find and remove it
About the command sudo nano /etc/paths
- It will open the /etc/paths file for editing with the nano editor. In the editor, you can view and edit system paths.
- In the pop-up editor, you can see the system path, and each path occupies a line. If you used GOPATH, you should be able to see it here
- Find the path you want to delete and use the keyboard delete key to delete it
- Press Control+O in the editor to save changes
- Press Control+X in the editor to exit the editor
About viewing the GOPATH path
echo $GOPATH
go env GOPATH
If deletion fails
- If the deletion fails,
go env
check the specific installation path of the go binary file and GOPATH
Free party-idea community version development go project – does not work
What should I do if the Go plugin cannot be found?
Go to the jetbrains plugin market and search for the Go plugin
- found to be incompatible with the currently running ide version
Checked many versions and found that IDEA Community Edition is not supported
Use the free VS-CODE
Install the Go plugin
- search and install
Create a Go project
mkdir myproject
cd myproject
go mod init myproject
Open the project in VS-Code
- Open the project you just created
Configure the Go extension of VSCode
- In VSCode press
command+shift+p
- enter
Go: Install/Update Tools
- select all and install
- The installation is successful, ready to go
test run go program
Write your first go code
- Create a go file
package main
import "fmt"
func main() {
fmt.Println("Hello, go!")
}
- run output