Home >Backend Development >Golang >How to install golang

How to install golang

PHPz
PHPzOriginal
2023-04-06 08:59:09735browse

Golang is a common programming language with efficient compilation speed and good concurrency performance. If you want to use Golang, installing the programming language is a must. In this article, we will introduce how to install Golang.

1. Download the installation package

Before installing Golang, we need to download the Golang installation file first. You can download the installation package for the corresponding platform from Golang’s official website [https://golang.org/dl/](https://golang.org/dl/);

In the download interface, you You can select the platform and operating system you need, and then click the Download button to start downloading.

2. Install Golang

After downloading the installation file, you can start installing Golang. During the installation process, you need to pay attention to the following steps:

Windows system

  1. Open the Golang installation filego.exe, and then click Run button. Then in the pop-up dialog box, click the Yes button to accept the license agreement.
  2. Set the installation path of Golang. In the pop-up dialog box, you can choose to use the default installation path (C:\Go), or you can choose a custom path. Then click the Install button to start the installation.
  3. Wait for Golang installation to complete. During the installation process, you can see Golang unpacking files and installing dependencies.
  4. After the installation is complete, you can choose to open Golang’s command line prompt “Command Prompt” or “Windows PowerShell” to start using Golang.

Linux system

  1. Open the terminal and enter the following command:
sudo tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz

where$VERSION is your Download the Golang version number, $OS is the operating system you are using, $ARCH is the processor architecture you are using.

  1. Then set the PATH environment variable and add Golang to the system path. You can use the following command:
export PATH=$PATH:/usr/local/go/bin

Or you can add the above command to the .bashrc file.

  1. Check whether Golang is successfully installed. You can enter the following command in the terminal:
go version

If you see the version number of Golang, then congratulations, Golang is installed successfully!

3. Set Golang environment variables

After Golang is installed, we also need to set Golang’s environment variables. This will ensure that Golang runs smoothly.

Windows System

  1. Right-click This PC/My Computer and select Properties.
  2. Select Advanced system settings and click Environment Variables.
  3. In the System Variables area, find the Path variable. Then click the Edit button.
  4. In the pop-up dialog box, click the New button, and then enter the Golang installation path C:\Go\bin.
  5. Click the OK button to save the variables and close the dialog box.
  6. Open Command Prompt or Windows PowerShell, enter the following command to test whether Golang is normal:
go version

Linux system

  1. Open a terminal and enter the following command to edit the .bashrc file:
nano ~/.bashrc
  1. Add the following at the bottom of the .bashrc file Code:
export PATH=$PATH:/usr/local/go/bin
  1. Press Ctrl X to exit editing, then enter Y to save the file.
  2. Enter the following command to make the environment variable take effect:
source ~/.bashrc
  1. Open the terminal and enter the following command to test whether Golang is normal:
go version

To Here, we have learned how to install Golang and set environment variables. If you encounter problems, you can find help in community discussions, such as [GolangCN Forum](https://gocn.vip/).

The above is the detailed content of How to install golang. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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