gopath_GOPATH解释

gopath

As written in How to Write Go Code,

如《 如何编写Go代码》中所述

Go programmers typically keep all their Go code in a single workspace.

Go程序员通常将所有Go代码保存在一个工作区中。

A workspace contains many version control repositories (managed by Git, for example).

工作区包含许多版本控制存储库(例如,由Git管理)。

Each repository contains one or more packages.

每个存储库包含一个或多个软件包。

The GOPATH environment variable specifies the location of your workspace. That’s where you find the Go tools, where you develop and where you install 3rd party packages and binaries.

GOPATH环境变量指定工作空间的位置。 在这里可以找到Go工具,在这里可以开发并在其中安装3rd party软件包和二进制文件。

As of Go 1.8, if you don’t set a GOPATH, the default will be used. In older releases had to set it explicitly, but for ease of use, a default has been introduced. By default the value of GOPATH is

从Go 1.8开始,如果您未设置GOPATH ,则将使用默认值。 在较早的版本中,必须明确设置它,但是为了易于使用,引入了默认设置。 默认情况下, GOPATH值为

  • $HOME/go on Unix-like systems

    $HOME/go在类似Unix的系统上

  • %USERPROFILE%\go on Windows

    在Windows上为%USERPROFILE%\go

This means that on macOS all your Go code will be put in the /go folder in your home directory.

这意味着在macOS上,您所有的Go代码都将放在主目录的/go文件夹中。

This is the most common setup, but you might also choose to use your home directory as GOPATH.

这是最常见的设置,但是您也可以选择将主目录用作GOPATH

Libraries installed using go get will be put in $GOPATH/src

使用go get安装的库将放在$GOPATH/src

Commands installed using go get will be put in $GOPATH/bin

使用go get安装的命令将放在$GOPATH/bin

Speaking of commands, you need to add $GOPATH/bin to your PATH to execute any binary installed in $GOPATH/bin, or you need to type $GOPATH/bin/the-command. Add this to your ~/.bash_profile or ~/.zshrc (or whatever shell you use) on *nix:

说到命令,您需要将$GOPATH/bin添加到PATH以执行安装在$GOPATH/bin任何二进制文件,或者需要键入$GOPATH/bin/the-command 。 将其添加到* nix上的~/.bash_profile~/.zshrc (或使用的任何shell)中:

export PATH=$GOPATH/bin:$PATH

A quick way to know what is your current GOPATH is running

一种快速了解您当前运行的GOPATH方法

go env GOPATH

Changing the GOPATH is easy, add this to your shell config file:

更改GOPATH很容易,将其添加到您的Shell配置文件中:

export GOPATH=$HOME/another-go-path

(Here’s how to set the PATH or GOPATH on Windows)

( 以下是在Windows上设置PATH或GOPATH的方法 )

参考文献 (References)

https://github.com/golang/go/wiki/SettingGOPATH https://golang.org/doc/code.html#GOPATH https://github.com/golang/go/wiki/GOPATH

https://github.com/golang/go/wiki/SettingGOPATH https://golang.org/doc/code.html#GOPATH https://github.com/golang/go/wiki/GOPATH

翻译自: https://flaviocopes.com/go-gopath/

gopath

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值