As a developer, it is necessary to install the golang environment. On a mac, installing the golang environment is also very simple. This article will introduce how to install the golang environment on mac.
Install Xcode
Before installing golang, you need to install Xcode. Xcode is an integrated development environment (IDE) launched by Apple that can be used to develop macOS, iOS, watchOS, and tvOS application development tools.
If you have already installed Xcode, you can skip this step.
Search Xcode in the app store, download and install it. If you have already installed Xcode, it is recommended to update to the latest version.
Install Homebrew
Homebrew is a macOS package manager that can easily install and update software. Therefore, we can use Homebrew to install golang.
Enter the following command in the terminal to install Homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Install golang
Enter the following command in the terminal to install golang:
brew install go
At this time , golang has been installed. You can enter the following command in the terminal to check the installation of golang:
go version
Set environment variables
After completing the installation of golang, you need to set the environment variables. Enter the following command in the terminal:
export GOPATH=$HOME/go export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
The above command will create a golang workspace in the ~/go
directory, and add the golang execution file path to the PATH variable.
If you want it to take effect permanently, you can add the above command to the ~/.bash_profile
file.
Using goland
Installing goland is optional. goland is a golang integrated development environment (IDE) launched by JetBrains, which can improve development efficiency.
After downloading the goland DMG file, drag it to the Applications folder to complete the installation.
After opening goland, click "Create New Project", select "Go Module", and fill in your project name in the input box below the project name.
Click the create button and the project will be automatically initialized and opened in goland.
Conclusion
This article introduces how to install golang on mac and use it in goland. Hope this article can help you.
The above is the detailed content of mac installation golang environment. For more information, please follow other related articles on the PHP Chinese website!