GO 安装
来源:互联网 发布:好帮手服装软件 编辑:程序博客网 时间:2024/04/26 07:09
Install the Go tools ¶
If you are upgrading from an older version of Go you must first remove the existing version.
Linux, Mac OS X, and FreeBSD tarballs ¶
Download the archive and extract it into/usr/local
, creating a Go tree in /usr/local/go
. For example:
tar -C /usr/local -xzf go1.9.linux-amd64.tar.gz
Choose the archive file appropriate for your installation. For instance, if you are installing Go version 1.2.1 for 64-bit x86 on Linux, the archive you want is calledgo1.2.1.linux-amd64.tar.gz
.
(Typically these commands must be run as root or through sudo
.)
Add /usr/local/go/bin
to the PATH
environment variable. You can do this by adding this line to your/etc/profile
(for a system-wide installation) or $HOME/.profile
:
export PATH=$PATH:/usr/local/go/bin
Installing to a custom location
The Go binary distributions assume they will be installed in /usr/local/go
(orc:\Go
under Windows), but it is possible to install the Go tools to a different location. In this case you must set theGOROOT
environment variable to point to the directory in which it was installed.
For example, if you installed Go to your home directory you should add commands like the following to$HOME/.profile
:
export GOROOT=$HOME/go1.Xexport PATH=$PATH:$GOROOT/bin
Note: GOROOT
must be set only when installing to a custom location.
Mac OS X package installer ¶
Download the package file, open it, and follow the prompts to install the Go tools. The package installs the Go distribution to/usr/local/go
.
The package should put the /usr/local/go/bin
directory in your PATH
environment variable. You may need to restart any open Terminal sessions for the change to take effect.
Windows ¶
The Go project provides two installation options for Windows users (besidesinstalling from source): a zip archive that requires you to set some environment variables and an MSI installer that configures your installation automatically.
MSI installer
Open the MSI file and follow the prompts to install the Go tools. By default, the installer puts the Go distribution inc:\Go
.
The installer should put the c:\Go\bin
directory in your PATH
environment variable. You may need to restart any open command prompts for the change to take effect.
Zip archive
Download the zip file and extract it into the directory of your choice (we suggestc:\Go
).
If you chose a directory other than c:\Go
, you must set the GOROOT
environment variable to your chosen path.
Add the bin
subdirectory of your Go root (for example, c:\Go\bin
) to yourPATH
environment variable.
Setting environment variables under Windows
Under Windows, you may set environment variables through the "Environment Variables" button on the "Advanced" tab of the "System" control panel. Some versions of Windows provide this control panel through the "Advanced System Settings" option inside the "System" control panel.
Test your installation ¶
Check that Go is installed correctly by setting up a workspace and building a simple program, as follows.
Create your workspace directory, $HOME/go
%USERPROFILE%\go
. (If you'd like to use a different directory, you will need toset the GOPATH
environment variable.)
Next, make the directory src/hello
inside your workspace, and in that directory create a file namedhello.go
that looks like:
package mainimport "fmt"func main() { fmt.Printf("hello, world\n")}
Then build it with the go
tool:
$ cd $HOME/go/src/hello$ go build
C:\> cd %USERPROFILE%\go\src\helloC:\Users\Gopher\go\src\hello> go build
The command above will build an executable named hello
hello.exe
in the directory alongside your source code. Execute it to see the greeting:
$ ./hellohello, world
C:\Users\Gopher\go\src\hello> hellohello, world
If you see the "hello, world" message then your Go installation is working.
You can run go
install
to install the binary into your workspace'sbin
directory or go
clean
to remove it.
Before rushing off to write Go code please read the How to Write Go Code document, which describes some essential concepts about using the Go tools.
Uninstalling Go ¶
To remove an existing Go installation from your system delete the go
directory. This is usually/usr/local/go
under Linux, Mac OS X, and FreeBSD or c:\Go
under Windows.
You should also remove the Go bin
directory from your PATH
environment variable. Under Linux and FreeBSD you should edit/etc/profile
or $HOME/.profile
. If you installed Go with theMac OS X package then you should remove the /etc/paths.d/go
file. Windows users should read the section aboutsetting environment variables under Windows.
- Go 安装
- Go安装
- Go 安装
- go安装
- Go安装
- Go安装
- go安装
- GO 安装
- Go安装
- Go 安装
- Go语言安装 go oci
- Go语言安装 go oci
- google go 安装经历
- Go语言编译器安装
- Plan 9安装Go
- ubuntu 安装go语言包
- centos 安装go语言
- go 安装与使用
- 学好奥数必掌握的这4大方法!
- 设计师选择自由职业好还是全职工作好
- 操作系统面试重难点总结
- Linux解决Warning: mysql_connect(): Headers and client library minor version mismatch. 警告 标签: linuxCen
- 初学者必读的Linux入门到精通
- GO 安装
- Rainet物联网云平台解决方案
- Displaying Fourier transforms in OpenCV
- jsp中普通按钮如何提交form表单
- SVG视野
- ubuntu 更新错误 修复
- 【前端知识点】CSS知识部分重点整理
- SpringMVC(1)--快速学习入门
- 软键盘显示隐藏事件监听