Home  >  Article  >  Backend Development  >  How to install golang on linux

How to install golang on linux

PHPz
PHPzOriginal
2023-04-24 14:46:461659browse

How to install Golang on Linux

Golang is a programming language developed by Google, and it is favored by many developers. Compared to other programming languages, Golang has excellent concurrency and network programming capabilities. Its efficiency and stability also make it widely used in cloud computing, network programming, distributed systems and other fields. It is very easy to install Golang on Linux systems. This article will introduce how to install Golang on Ubuntu and CentOS.

1. Install Golang on Ubuntu

Ubuntu is a Debian-based Linux distribution, so installing Golang on Ubuntu can be done using the Debian-based package manager apt.

  1. Open the terminal:

The shortcut key to open the terminal in Ubuntu is Ctrl Alt T.

  1. Update Apt repository:

Enter the following command in the terminal:

sudo apt update

This command will update the system's Apt repository.

  1. Install Golang:

In Ubuntu, you can use the following command to install Golang:

sudo apt install golang

Download and install the latest Golang from the Apt repository Version.

  1. Verify whether Golang is installed successfully:

Enter the following command in the terminal:

go version

If Golang is installed correctly, the current Golang version number.

2. Install Golang on CentOS

CentOS is a Linux distribution based on the same kernel as RHEL (Red Hat Enterprise Linux), so you can also use RPM package management to install Golang on CentOS. device to operate.

  1. Open the terminal:

The shortcut key to open the terminal in CentOS is Ctrl Alt T.

  1. Install epel-release:

Enter the following command in the terminal:

sudo yum install epel-release

This command will install the epel-release extension library of CentOS.

  1. Install Git:

Enter the following command in the terminal:

sudo yum install git

Git is a code version control system, and Golang needs to rely on Git.

  1. Download and install Golang:

Enter the following command in the terminal:

wget https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.14.2.linux-amd64.tar.gz

This command will download Golang’s tar.gz compression from the Golang official website package and extract it to the /usr/local directory.

  1. Configure system environment variables:

To allow the system to find the installed Golang, you need to add /usr/local/go/bin to the system’s PATH environment variable middle. Enter the following command in the terminal:

echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
source ~/.bashrc

This command will add /usr/local/go/bin to the system’s PATH environment variable and load this new environment variable in the terminal.

  1. Verify whether Golang is installed successfully:

Enter the following command in the terminal:

go version

If Golang is installed correctly, the current Golang version number.

Conclusion

Installing Golang on a Linux system is very simple, whether it is on Ubuntu or CentOS, it can be installed through the package manager. Ubuntu uses Apt, CentOS uses RPM, and the installation is very convenient. Once Golang is successfully installed, you can start writing efficient, concurrent, and stable Go programs.

The above is the detailed content of How to install golang on linux. 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