Golang is an open source programming language developed by Google. It is designed to be simple and efficient, and is suitable for building high-performance applications. Before learning and using Golang, you first need to install the Golang development environment on your computer. This article will detail how to install Golang on different operating systems, with specific code examples.
First, you need to go to the Golang official website (https://golang.org/dl/) to download the applicable Installation package for Windows systems. Select the latest stable version to download and double-click the installation package to start the installation.
After the installation is complete, you need to configure environment variables. Right-click the computer icon, select "Properties" -> "Advanced System Settings" -> "Environment Variables", add a new variable GOPATH
in the system variables, the value is your Golang workspace path, Such as C:Goworkspace
. Then add the Golang bin directory to the system variable Path
, such as C:Go in
.
Open the command prompt and enter the go version
command. If the currently installed Golang version can be displayed, the installation is successful.
On the MacOS system, you can use Homebrew to install Golang. Open the terminal and execute the following command:
brew install go
After the installation is complete, you also need to configure environment variables. Enter the following command in the terminal:
echo "export GOPATH=$HOME/go" >> ~/.bash_profile echo "export PATH=$PATH:$GOPATH/bin" >> ~/.bash_profile source ~/.bash_profile
Enter the go version
command in the terminal to confirm that the installation is successful.
In most Linux distributions, you can use the package manager to install Golang. Taking Ubuntu as an example, open the terminal and execute the following command:
sudo apt-get update sudo apt-get install golang
Edit the ~/.bashrc
file and add the following content at the end of the file :
export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin
Then execute the following command to make the configuration take effect:
source ~/.bashrc
Enter the go version
command in the terminal to confirm the installation success.
Through the above steps, we successfully installed Golang on Windows, MacOS and Linux operating systems and configured the environment. Now you can start writing Golang programs and enjoy the fun of this powerful and elegant programming language!
The above is the detailed content of Golang Installation Guide: Choosing the Right Operating System Version. For more information, please follow other related articles on the PHP Chinese website!