【转】GO 环境配置
2016-01-17 23:14
393 查看
Getting Started
Install the Go toolsTest your installationUninstalling GoGetting help |
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.5.3.linux-amd64.tar.gz
(Typically these commands must be run as root or through
sudo.)
Add
/usr/local/go/binto the
PATHenvironment 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(or
c:\Gounder
Windows), but it is possible to install the Go tools to a different location. In this case you must set the
GOROOTenvironment variable to point to the directory in which it was installed.
For example, if you installed Go to your home directory you should add the following commands to
$HOME/.profile:
export GOROOT=$HOME/go export PATH=$PATH:$GOROOT/bin
Note:
GOROOTmust be set only when installing to a custom location.
Test your installation
Check that Go is installed correctly by setting up a workspace and building a simple program, as follows.Create a directory to contain your workspace,
$HOME/workfor example,
and set the
GOPATHenvironment variable to point to that location.
$ export GOPATH=$HOME/work
You should put the above command in your shell startup script (
$HOME/.profilefor example) or, if you use Windows, follow the instructions
above to set the
GOPATHenvironment variable on your system.
Next, make the directories
src/github.com/user/helloinside your workspace (if you use GitHub, substitute your user name for
user),
and inside the
hellodirectory create a file named
hello.gowith the following contents:
package main import "fmt" func main() { fmt.Printf("hello, world\n") }
Then compile it with the
gotool:
$ go install github.com/user/hello
The above command will put an executable command named
hello(or
hello.exe) inside the
bindirectory
of your workspace. Execute the command to see the greeting:
$ $GOPATH/bin/hello hello, world
If you see the "hello, world" message then your Go installation is working.
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 godirectory. This is usually
/usr/local/gounder Linux, Mac OS
X, and FreeBSD or
c:\Gounder Windows.
You should also remove the Go
bindirectory from your
PATHenvironment variable. Under Linux and FreeBSD you should edit
/etc/profileor
$HOME/.profile.
If you installed Go with the Mac OS X package then you should remove the
/etc/paths.d/gofile.
Windows users should read the section about setting environment variables under Windows.
Getting help
For real-time help, ask the helpful gophers in #go-nutson the Freenode IRC server.
The official mailing list for discussion of the Go language is Go Nuts.
Report bugs using the Go issue tracker.
相关文章推荐
- [LightOJ 1030] Discovering Gold (概率DP)
- django 学习-18 用户管理Auth系统使用
- django 学习-17 Django会话Session
- Codeforces 616D Longest k-Good Segment(双指针)
- Good Bye 2015
- Introducing Go - O'Reilly 2016 阅读笔记
- leangoo,因小而美!
- Ubuntu 13.10 用sogou拼音替换ibus-转
- Ubuntu 12.04中设置安装Google拼音输入法
- django 通过表单传递数据到后台
- django url到views参数传递
- G面经prepare: BuyGoods
- golang gdb调试教程
- 初识DragonBoard 410c
- django如何在 search_fields 中包含外键字段
- django - form
- django 前台-后台传输数据
- django views显示中文
- django后台页面标题定制
- django中配置markdown