Home > Article > Backend Development > Let’s talk about the steps of offline installation of golang
In some scenarios, we need to install golang offline. Offline installation refers to installation without an Internet connection. This article will introduce the steps for offline installation of golang.
Step 1: Download the golang binary file
First, we need to visit the Golang official website to download the binary file that matches our operating system. The address is: https://golang.org/dl/. Before downloading the file, you need to check whether your operating system is 64-bit or 32-bit. =
Next, we need to import the downloaded file into an offline environment.
Step 2: Move the files to the offline environment
We need to decompress the downloaded binary file package (golang-X.X.X.X) and move it to our offline environment. Assuming we are using the CentOS 7 operating system and the unzipped folder is named "go", we can move it to our /opt directory as follows:
$ sudo tar -C /usr/local -xzf go1.16.5.linux-amd64.tar.gz
In this step, " go1.16.5.linux-amd64.tar.gz" is the name of the binary file package we downloaded and needs to be replaced according to the actual situation.
Step 3: Set environment variables
Now that we have moved the golang binary file to the offline environment, we need to configure it into the system's environment variables. This is because the system cannot find the golang executable file by default, so we need to add its path to the system's PATH environment variable.
We need to edit the /etc/profile file and add the following code at the end of the file:
export GOROOT=/usr/local/go export GOPATH=$HOME/go export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
In the above code, $GOPATH represents the path to write the golang program source code. By default, it will be set to the $HOME/go directory. You can use the echo $GOPATH command to see if its value is correct.
We use the source command to make our configuration take effect immediately:
$ source /etc/profile
Step 4: Verify the installation of golang
After everything is done, we can use the golang command to verify the installation of golang Condition. We need to enter in the command line:
$ go version
If golang is installed correctly, we will see the version information of golang.
At this point, we have successfully installed golang in an offline environment. Hope this article can be helpful to you!
The above is the detailed content of Let’s talk about the steps of offline installation of golang. For more information, please follow other related articles on the PHP Chinese website!