Mac-install and configure go language development environment

Choose the right version

Go language official website
image.png

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

image.png

Configure multiple versions

  1. Download different versions from the official website
  2. Extract to any directoryex: /usr/local/go1.17
  3. Modify environment variablesopen -e .bash_profile
  4. 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
  1. make it effectivesource .bash_profile
  2. Successful installation
  3. image.png
  4. 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 envcheck 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?

image.png

Go to the jetbrains plugin market and search for the Go plugin

  • found to be incompatible with the currently running ide version

image.png

Checked many versions and found that IDEA Community Edition is not supported

image.png

Use the free VS-CODE

Download VS-code

Install the Go plugin

  • search and install

image.png

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

  1. In VSCode presscommand+shift+p
  2. enterGo: Install/Update Tools
  3. image.png
  4. select all and install
    1. image.png
    2. The installation is successful, ready to go

test run go program

Write your first go code

  1. Create a go file
  2. image.png
package main

import "fmt"

func main() {
    
    
    fmt.Println("Hello, go!")
}
  1. run output
  2. image.png

end flowering

Guess you like

Origin blog.csdn.net/GoNewWay/article/details/130820280