Golang is a fast, reliable, and simple programming language. Because of its excellent performance and ease of use, it has become one of the preferred languages for software developers. However, when developing with Golang, we usually need to install the official Golang environment to be able to compile and run the code locally. In many cases, we may not have direct access to the official website or may not want to install Golang online. Therefore, this article will introduce how to install the Golang environment offline.
1. Download the Golang installation package
First, we need to download the Golang installation package from the official website. In order to achieve offline installation, we need to download all required components and save them locally.
Multiple versions of Golang are provided on the official website. We can choose to download the corresponding version according to our needs. In this case, we choose to download the latest version of Golang (currently 1.17).
In the download page, we can choose to download the installation package suitable for our own operating system, such as Windows, Linux or Mac OS X version installation package. Note that we need to download the installation package suitable for our own CPU architecture, such as 64-bit or 32-bit version.
After the download is complete, we can save the installation packages locally, or upload them to our own server for offline installation on other machines.
2. Install the Golang environment
Once we have prepared the required installation packages, we can start installing the Golang environment. Here are the steps to install Golang on Windows and Linux systems.
Install Golang on Windows:
go version
If the installation is successful , we will see the version number of Golang.
Install Golang on Linux:
tar -C /usr/local -xzf go1.17.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
go version
If the installation is successful, we will see the version number of Golang.
3. Configure the Golang environment
After installing Golang, we need to perform some simple configurations to ensure that the Golang environment can work properly.
First, we need to set the GOROOT environment variable. GOROOT refers to the root directory of Golang installation, usually /usr/local/go or C:Go. We can set the GOROOT environment variable in the following ways:
On Windows:
On Linux:
export GOROOT=/usr/local/go
source ~/.bashrc
or source /etc/bashrc
In addition, we also need to set GOPATH to a directory we like. GOPATH is a directory that contains all Golang libraries and binaries. We can set the GOPATH environment variable in the following ways:
On Windows:
On Linux:
export GOPATH=$HOME/go
mkdir $HOME/go
source ~/.bashrc
or source /etc/bashrc
After setting the environment variables, we can start writing and running code using Golang.
4. Summary
In this article, we introduced how to download the Golang installation package, install the Golang environment offline, and configure Golang's environment variables. Through the above steps, we can install Golang in an offline environment, compile and run the code easily and quickly, and avoid the inconvenience of online downloading and installation. If you are a Golang developer, I hope this article can help you.
The above is the detailed content of Install golang offline. For more information, please follow other related articles on the PHP Chinese website!