How to install Golang environment on different operating systems

PHPz
Release: 2023-04-10 09:10:00
Original
842 people have browsed it

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.

Windows

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.

Linux

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
Copy after login

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
Copy after login

Effective command: source ~/.bashrc. You can then enter the go version command on the command line to verify whether the installation is successful.

Mac OS

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)"
Copy after login

Homebrew After the installation is complete, enter the following command to install Golang:

brew install golang
Copy after login

Afterwards, set the environment variables by modifying ~/.bash_profileFile to set:

export GOROOT=/usr/local/opt/go/libexec
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!