Home >Backend Development >Golang >How to install Golang environment on different operating systems
With the wide application of Golang in development, more and more people are learning and using Golang. Installing the Golang environment is one of the prerequisites for using Golang development. This article will introduce how to install Golang environment on different operating systems.
It is easiest to install Golang on the Windows platform. First download the installation file of the corresponding version from the official website. When installing, select custom installation, set the GOROOT (installation directory) and GOPATH (working directory) environment variables, and be sure to add GOPATH to the system environment variables.
After the installation is complete, you can enter the go version
command through the command line to verify whether the installation is successful.
Installing Golang on Linux is relatively simple, but it should be noted that different Linux distributions may be slightly different. Here we take the Ubuntu system as an example.
First you need to install Golang through the apt-get command:
sudo apt-get update sudo apt-get install golang
Then set the GOROOT environment variable, you can modify the /etc/profile
file or ~/. bashrc
file to set. Here is an example of modifying ~/.bashrc
:
export GOROOT=/usr/lib/go export GOPATH=$HOME/go export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
Effective command: source ~/.bashrc
. You can then enter the go version
command on the command line to verify whether the installation is successful.
Installing Golang on Mac OS requires installing Homebrew first. If you have already installed it, you can skip this step. Enter the following command in the terminal to install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Homebrew After the installation is complete, enter the following command to install Golang:
brew install golang
Afterwards, set the environment variables by modifying ~/.bash_profile
File to set:
export GOROOT=/usr/local/opt/go/libexec export GOPATH=$HOME/go export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
Effective command: source ~/.bash_profile
. You can then enter the go version
command on the command line to verify whether the installation is successful.
The above is how to install the Golang environment. I hope it will be helpful to everyone.
The above is the detailed content of How to install Golang environment on different operating systems. For more information, please follow other related articles on the PHP Chinese website!