Home > Backend Development > Golang > How to install golang 1.9

How to install golang 1.9

PHPz
Release: 2023-04-25 13:54:44
Original
567 people have browsed it

Golang is an open source programming language developed by Google. Its main features are fast compilation, concurrent programming and memory safety. With the advent of the era of cloud computing and big data, Golang is becoming more and more popular among developers. This article will introduce the installation method of Golang 1.9.

  1. Download Golang

The Golang official website provides binary distribution packages for each platform. We can download the version suitable for our own platform from the official website. The download address is: https://golang.org/dl/. On the download page, we can choose the version that suits our platform to download.

  1. Installing Golang

After downloading Golang, we need to unzip and move the unzipped folder to the appropriate location. For Unix/Linux operating system users, you can unzip the Golang folder to the /opt directory. For example:

$ tar -C /opt/ -xzf go1.9.linux-amd64.tar.gz
Copy after login

After decompression, we need to set the Golang environment variables. It can be set by editing the /etc/profile file or ~/.bashrc file:

export PATH=$PATH:/opt/go/bin
export GOPATH=/home/username/gopath
Copy after login

Among them, GOPATH is the working directory of Golang. It is recommended to set it to a non-system disk and create related directories. For example:

mkdir -p ~/gopath/src ~/gopath/pkg ~/gopath/bin
Copy after login
  1. Test installation

After the installation is completed, you can test whether Golang is installed successfully by running the following command:

$ go version
go version go1.9.1 linux/amd64
Copy after login

If the above prompt appears , it means that Golang has been successfully installed. At the same time, we can also test whether the basic functions of Golang are normal by using Golang tools:

$ cd ~/gopath/src
$ mkdir hello
$ cd hello
$ nano main.go
Copy after login

Enter the following content in the main.go file:

package main

import "fmt"

func main() {
    fmt.Println("Hello, world!")
}
Copy after login

Save and exit, then use the following Command to compile and run the program:

$ go build
$ ./hello
Hello, world!
Copy after login

The above command will generate an executable file named "hello" and output "Hello, world!".

  1. Install third-party package management tools

In Golang development, we often need to import third-party packages to implement some functions. In order to facilitate the management and use of these third-party packages, it is recommended to install a third-party package management tool, such as go get or glide. Take installing go get as an example:

$ go get -u github.com/golang/dep/cmd/dep
Copy after login

The above command will install the latest version of the dep package management tool and install it in the $GOPATH/bin directory. After the installation is complete, we can use the dep tool to manage our project dependencies.

Summary

Through the above steps, we can easily install Golang 1.9 and start using Golang for development. Of course, Golang has many other features and usages that we need to learn and use further.

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

Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template