How to install golang package

(*-*)浩
Release: 2019-12-27 11:05:26
Original
3187 people have browsed it

How to install golang package

Prerequisites for golang to install a third party

GOPATH must be set

linux                                                                                                                                                                                                                           to  (recommended learning: go)

vim /etc/profile
export GOROOT=/usr/local/go  // 设置为你自己的go安装目录
export GOPATH=$HOME/gocode   // 设置为自己的go项目的工作区间
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin  // 原路径后用冒号连接新路径

source /etc/profile  // 使文件立刻生效
Copy after login

mac

cd ~
vim .bash_profile
export GOROOT=/usr/local/opt/go\@1.9/libexec  //golang安装路径
export GOPATH=/usr/local/Cellar/go/1.7.6   // 工作路径
export GOBIN=$GOPATH/bin  // 可执行文件
export PATH=$PATH:$GOROOT/bin:$GOBIN  // path导入路径
source ~/.bash_profile  // 使文件立刻生效
Copy after login

window: GOPATH , additionally install git

In fact, linux and mac systems also require git, but both have git by default. Windows needs to be installed independently.

Go to the git official website to download git and install it

Then set the GOPATH:

Right-click my computer - Advanced System Settings - Environment variables, click [New] under system variables

Enter: Line 1: GOPATH Line 2: You specify the path, for example: D:\go\gopath (note to remove the semicolon at the end)

How to install the third package in golang

Automatic installation: install through go get xxx command

This command The remote third-party package will be downloaded and decompressed into the src folder in your GOPATH path, and the go install xxx command will be executed to install the package. As a result, the xxx.a file will be generated in the pkg folder in the GOPATH path

In fact, go get is a combination of git clone go install

As can be seen from the above, windows uses git when calling go get, so git must be installed first

Manual installation:

Download the package first, and create the corresponding path under gopath/src for the package according to the official download path of the package.

Pay attention to this step Very critical! The path of the third package in src cannot be placed in a folder arbitrarily, because there are references to other packages in the files inside the third-party package. If placed arbitrarily, the import path will become invalid.

Move the package to this path and execute the go install command to install this file

The above is the detailed content of How to install golang package. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template