Home > Article > Backend Development > How to run Golang on different operating systems
Golang (also known as Go) is an open source programming language developed by Google. Released in 2009, the language draws inspiration from C and C, but it is also influenced by many other programming languages. Golang is a statically typed programming language that aims to be efficient, concise, and reliable, while its syntax is designed to be easy to use and understand.
In this article, we will introduce how to run Golang on different operating systems.
First of all, to install Golang on Windows, the easiest and most recommended way is to download and install it from the official website. The download link is https://golang.org/dl/.
After the download is complete, double-click to open the installer and follow the instructions of the installation wizard. The installer will set the necessary system environment variables for you.
You can also install Golang using PowerShell, a command-line shell on Windows. You can perform the following steps:
Invoke-WebRequest -Uri "https://dl.google.com/go/go1.16.4.windows-amd64.msi" -OutFile go1.16.4.windows-amd64.msi msiexec.exe /i go1.16.4.windows-amd64.msi /quiet
Whether you download and install from the official website or install using PowerShell, you need to add the Golang bin directory to the system environment variables . Please follow the steps below:
sysdm.cpl
, and then press the Enter key to open the system properties Window;C:\ Go\bin
to your PATH (if you are using PowerShell, the path may be slightly different). Now you have Golang installed and configured on Windows!
You can use Homebrew to manage your Golang installation. Homebrew is a package manager on macOS. If Homebrew is not installed, open a terminal and execute the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Once Homebrew is installed, install Go by running the following command:
brew install go
Now you are installed on macOS Golang!
If you are using one of the supported Linux distributions such as Ubuntu, Debian, Fedora or CentOS, You can install Golang using the corresponding package manager.
To install Golang on Ubuntu and Debian, use the following command:
sudo apt update sudo apt install golang
To install Golang on Fedora, Please use the following command:
sudo dnf install golang
To install Golang on CentOS, please use the following command:
sudo yum install golang
If your Linux If the distribution does not support Golang or you want to install another version, you can install it manually.
~/go
; ~/go
directory; .bashrc
(if you are using bash) Or add the following lines to .zshrc
(if you are using zsh): export GOROOT=~/go export GOPATH=$HOME/work export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
source ~/.bashrc # Or your corresponding shell configuration file
Now, you have installed Golang on Linux!
No matter which operating system you are using, after installing Golang, you can create your first Golang program.
hello.go
; package main import "fmt" func main() { fmt.Println("Hello, world!") }
go run hello.go
You should see the output Hello, world!
.
Golang is a very popular programming language that is favored due to its efficiency, simplicity and reliability. In this article, we cover how to install and configure Golang on Windows, macOS, and Linux, as well as how to write and run your first Golang program.
The above is the detailed content of How to run Golang on different operating systems. For more information, please follow other related articles on the PHP Chinese website!