Home > Article > Backend Development > Install golang on Apple system
In recent years, Golang has become a very popular programming language among developers. Due to its excellent performance and easy maintenance, it is increasingly favored by developers and enterprises. When developing with Golang, it is especially important to be able to install and use this programming language on a Mac system. This article will introduce how to successfully install Golang on Apple systems.
First, we download the Golang installation package suitable for Mac system on the Golang official website. Official website address: https://golang.org/dl/. After the download is complete, we enter the directory and open the downloaded pkg file:
$ cd ~/Downloads
$ open go*.pkg
After opening the .pkg file, we will see the Golang installation interface. After pressing the "Continue" button, you will enter the installation wizard. Follow the prompts step by step to install Golang on our computer.
After the installation is complete, we need to configure the environment variables to use Golang in the terminal. First, open the "~/.bash_profile" file:
$ vim ~/.bash_profile
Then add the following code to the file:
export GOPATH=$HOME/ go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
After modification, execute the following command to make our environment variables take effect:
$ source ~/.bash_profile
We can use the following command to test the Golang installation results:
$ go version
If the Golang version information is successfully output, the installation has been successfully completed:
$ go version
go version ...
Finally, we need to install some necessary third-party libraries after the installation is complete. We can install it through the following command:
$ go get github.com/gin-gonic/gin
After the installation is complete, we can execute the following command to test:
$ go run main.go
At this point, we have successfully installed Golang on the Apple system and learned the basic configuration and download and installation methods of third-party packages.
Summary
Installing Golang on a Mac system is very simple. First we need to download the installation package, then perform the installation operation, configure the environment variables so that Golang can be used in the command line, and finally install the necessary third-party libraries. In the process of learning to use Golang, it will be very beneficial to have a thorough understanding of the content covered in this article.
The above is the detailed content of Install golang on Apple system. For more information, please follow other related articles on the PHP Chinese website!