Install golang on Apple system

WBOY
Release: 2023-05-09 21:04:37
Original
667 people have browsed it

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.

  1. Download the installation package

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

  1. Install Golang

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.

  1. Configure environment variables

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

  1. Test the installation results

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 ...

  1. Install third-party packages

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template