Go can be installed in a variety of ways, and you can choose which one you prefer. Here are the three most common installation methods:

  • Go source installation: This is a standard way to install software. For regular users of Unix-like systems, especially developers, installation from source is customizable.
  • Go standard package installation: Go provides convenient installation packages for Windows, Linux, and Mac operating systems. This way is suitable for quick installation, you can download the corresponding installation package according to your system bit, all the way next can easily install. Recommend this approach
  • Third party tool installation: There are many convenient third party software package tools, such as Ubuntu apt-get and wget, Mac Homebrew, etc. This installation method is suitable for those familiar with the corresponding system users.

Finally, if you want to install multiple versions of Go on the same system, you can refer to the third-party tool GVM, which currently does the best job of this unless you know how to handle it.

Go source code installation

Go 1.5 completely removes C code, Runtime, Compiler, and Linker are all written by Go, implementing bootloader. You only need to have the previous version installed to install from source.

Before Go 1.5, some parts of the Go source code were written in Plan 9 C and AT&T assembly, so if you want to install from the source code, you must install the C compiler.

On the Mac, once you have Xcode installed, you already have a compilation tool.

On uniX-like systems, you need to install tools such as GCC. For Ubuntu, run sudo apt-get install GCC libc6-dev to install the compilation tool.

On Windows, you need to install MinGW, then install GCC from MinGW and set the appropriate environment variables.

You can download the source code directly from goversion.src.tar. gz, unzip it to $HOME, and execute the following code:

cd go/src

./all.bash

The installation is successful only when “all TESTS PASSED” is displayed after the all.bash command is run.

The uniX-style command above is installed in a similar way under Windows, except that all.bat is run and the compiler is MinGW GCC.

If you’re a Mac or Unix user and you need to set a couple of environment variables, if you want them to work even after you restart, write the following command to.bashrc or.zshrc,

export GOPATH=$HOME/gopath

export PATH=$PATH:$HOME/go/bin:$GOPATH/bin

If you are writing to a file, remember to run bash. bashrc or bash. ZSHRC for the Settings to take effect immediately.

If you are running Windows, you need to set environment variables. Add the corresponding go directory to path and set the gopath variable.

When you complete the setup, type go in the command line, and if you see the following image, you have successfully installed

If the Go Usage message appears, it indicates that Go has been installed successfully. If the command does not exist, check to see if your PATH environment change contains the Go installation directory.

As of Go 1.8, the GOPATH environment variable now has a default value if it is not set. It defaults to $HOME/go on Unix and %USERPROFILE%/go on Windows.

GOPATH is explained in more detail in the following sections

Two, Go standard package installation

By default, these packages will be installed in the following directory: /usr/local/go (Windows: C :\Go). Of course, you can change their installation location, but then you must set the following information in your environment variables:

export GOROOT=$HOME/go

export GOPATH=$HOME/gopath

export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

The above commands are best for Mac and Unix users to write.bashrc or.zshrc files, and of course for Windows users to write environment variables.

How can I determine whether MY operating system is 32-bit or 64-bit?

Our next Go installation will need to determine the number of bits of the operating system, so in this section we will first determine our system type.

For Windows users, press Win+R to run CMD, enter SystemInfo, and press Enter. After a while, some system information will be displayed. If X64-based PC is displayed in the System Type row, the system is a 64-bit system. If x86-based PC is displayed, it is a 32-bit system.

Mac system users are advised to Go straight to 64-bit, as the Mac OS X version supported by Go no longer supports pure 32-bit processors.

Linux users can run the arch(uname -m) command in Terminal to view system information.

64-bit system display

x86_64

32-bit system display

i386

Mac installation

Darwin-386-osx10.8.pkg for 32 – bit oss, go1.8.3.darwin-amd64.pkg for 64 – bit oss, darwin-amd64 – PKG for 32 – bit oss, go1.8.3.darwin-amd64 – PKG for 64 – bit oss, darwin-amd64 – PKG for 32 – bit oss, go1.8.3.darwin-amd64 – PKG for 32 – bit oss, go1.8.3.darwin-amd64 – PKG for 64 – bit oss, By default, you have added ~/go/bin to your PATH. At this point, open the terminal and type go

If you see a picture similar to the above source code installation success, it indicates that the installation is successful

If the go Usage message appears, it indicates that go has been installed successfully. If the command does not exist, check to see if your PATH environment change contains the go installation directory.

Linux installation

Gz for 32-bit systems and go1.8.3.linux-amd64.tar.gz for 64-bit systems.

Assume that the directory where you want to install Go is $GO_INSTALL_DIR, and replace it with the corresponding directory path.

Gz package to the installation directory: tar ZXVF go1.8.3.linux-amd64.tar.gz -c $GO_INSTALL_DIR.

To set PATH, export PATH=$PATH:$GO_INSTALL_DIR/go/bin

And then go

If the go Usage message appears, it indicates that go has been installed successfully. If the command does not exist, check to see if your PATH environment change contains the go installation directory.

Windows installation

Visit the Golang download page and select the MSI installation package whose name contains Windows-386 for 32-bit or Windows-AMD64 for 64-bit. Do not change the default installation directory C:\Go\, otherwise you will not be able to execute your Go code. After the installation is complete, the bin directory C:\Go\bin\ in the Go installation directory is added to the environment variable Path by default, and the environment variable GOROOT is added with the value of the Go installation root directory C:\Go\.

Verify that the installation is successful

Enter CMD to open the command line tool, and enter Go at the prompt to check whether the Usage information is displayed. Type CD %GOROOT% to see if you can Go to the Go installation directory. If they are successful, the installation is successful.

If not, check the values of the environment variables Path and GOROOT above. If no, uninstall it and reinstall it. If yes, restart the computer and try again.

Third party tool installation

GVM

GVM is a third-party Go multi-version management tool, similar to the RVM tool in Ruby. Easy to use, install GVM using the following command:

bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)

Once installed, we can install Go:

GVM install go1.8.3

GVM use go1.8.3

You can also use the following command to save the trouble of calling GVM use every time: GVM use go1.8.3 –default

After executing the above command, environment variables such as GOPATH and GOROOT are automatically set so that they can be used directly.

apt-get

Git Mercurial installation Ubuntu is the most popular Linux desktop system, and git Mercurial installation can be done with the following command:

sudo apt-get install python-software-properties

sudo add-apt-repository ppa:gophers/go

sudo apt-get update

sudo apt-get install golang-stable git-core mercurial

wget

Wget HTTP: / / https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz

Run the following command to run the following command: sudo tar -xzf go1.8.3.linux-amd64.tar.gz -c /usr/local

Configure environment variables:

export GOROOT=/usr/local/go

export GOBIN=$GOROOT/bin

export PATH=$PATH:$GOBIN

Export GOPATH=$HOME/ GOPATH (Optional)

Or use:

sudo vim /etc/profile

And add the following:

export GOROOT=/usr/local/go

export GOBIN=$GOROOT/bin

export PATH=$PATH:$GOBIN

Export GOPATH=$HOME/ GOPATH (Optional)

Reload the profile file

source /etc/profile

homebrew

Git Mercurial homebrew is the most widely used management software installation tool for Mac systems. Git Mercurial is the most widely used management software installation tool for Mac systems. Git Mercurial is the most widely used management software installation tool for Mac systems.

1. Install homebrew

/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

2. Install the go

brew update && brew upgrade

brew install go

brew install git

Brew Install Mercurial // Optional