ubuntu安装Go

安装

If you are upgrading from an older version of Go you must first remove the existing version.
如果安装的有老版本,需要先删除,方法见后面。
下载安装包,这里下的是1.10的

$ wget https://dl.google.com/go/go1.10.linux-amd64.tar.gz

extract it into /usr/local, creating a Go tree in /usr/local/go. For example:

tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.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 called go1.2.1.linux-amd64.tar.gz.
像这样:

$ sudo tar -C /usr/local -xzf go1.10.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:exportPATH= H O M E / . p r o f i l e : 添 加 环 境 变 量 ‘ e x p o r t P A T H = PATH:/usr/local/go/bin到/etc/profile(全系统安装)或 .bashrc,这里我放在.bashrc中。

export PATH=$PATH:/usr/local/go/bin

The Go binary distributions assume they will be installed in /usr/local/go (or c:\Go under Windows), but it is possible to install the Go tools to a different location. In this case you must set the GOROOT 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:
安装在其他位置,需要设置goroot环境变量

export GOROOT=$HOME/go1.X
export PATH=$PATH:$GOROOT/bin

工作目录也必须设置正确,不然编译会有问题。
设置go的工作目录
Go代码必须放在工作目录内。它其实就是一个目录,其中包含三个子目录:
src 目录包含Go的源文件,它们被组织成包(每个目录都对应一个包)
pkg 目录包含包对象
bin 目录包含可执行命令
将工作空间添加到环境变量中

export GOPATH=$HOME/gowork

将bin目录加入环境变量里

export PATH=$PATH:$GOPATH/bin

至此go的安装结束

测试安装
Next, make the directory src/hello inside your workspace, and in that directory create a file named hello.go that looks like:

package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")
}

卸载

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 the Mac OS X package then you should remove the /etc/paths.d/go file. Windows users should read the section about setting environment variables under Windows.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值