当前位置:网站首页>GoLand environment variable configuration
GoLand environment variable configuration
2022-07-04 08:55:00 【liyinchi1988】
【linux】
1. Download binary package
wget https://golang.google.cn/dl/go1.17.6.linux-amd64.tar.gz2. Extract the downloaded binary package to /usr/local Catalog
cd /usr/local tar -zxvf go1.17.6.linux-amd64.tar.gz3. take /usr/local/go/bin Add directory to PATH environment variable
(1) Edit profile
cd ~ vim /etc/profile(2) Add content
# goland
export GOROOT=/usr/local/go
export GOPATH=/usr/local/go/gopath/
export PATH=$PATH:$GOROOT/binBe careful :GOPATH The value of cannot be the same as GOROOT identical
(3) stay GPPATH New under the directory bin、pkg、src Three folders
cd /usr/local/go/gopath/
mkdir bin
mkdir pkg
mkdir src(4) Refresh profile
source /etc/profile【mac】
(1) download pkg Installation package
(2) Modify the configuration file .bash_profile
vim .bash_profileexport GOROOT=/usr/local/go
export GOPATH=/usr/local/go/gopath/
export PATH=$PATH:$GOROOT/binremarks :GOPATH Decide to rely on storage location
(2) stay GPPATH New under the directory bin、pkg、src Three folders
cd /usr/local/go/gopath/
mkdir bin
mkdir pkg
mkdir src(3) Refresh profile
source .bash_profile【Windows】
(1) To configure GOROOT
GOROOT The variable value of is GO Installation directory /usr/local/go
(2) To configure GOPATH
GOPATH The variable value of is stored Go The path of language project /usr/local/go/Go_WorkSpace
In the above GOPATH In the corresponding path , newly build bin、pkg、src Three folders , See the picture below :

(3) To configure Path
Path There are configuration information of other installers in , Here's one more GO Of bin Catalog /usr/local/go/bin
(4) Verify that the configuration is successful
go env(5) View the installed by command Go Version of
go version
【 help 】
go help gopath
【 matters needing attention 】
- Depending on the installation location GOPATH=/usr/local/go/gopath
- GOPATH It can be a list of directories , perform go get Downloaded third-party libraries , Generally, it will be downloaded to the first directory of the list
- Need to put GOPATH The executable directory in is also configured into the environment variable , Otherwise, the third party you download by yourself go Tools will not work
- GOPATH Must contain src、pkg、bin Three files
go Dependency package management
【 Install third party dependencies 】
go install github.com/xuri/excelize
go get github.com/xuri/excelizeModular installation
go get github.com/xuri/excelize/v2(1) If prompted “go get: module github.com/xuri/excelize/v2: Get "https://proxy.golang.org/github.com/xuri/excelize/v2/@v/list": dial tcp 142.251.42.241:443: i/o timeout”
terms of settlement : Turn on wall climbing or set Domestic mirror
(2) If prompted “go: could not create module cache: mkdir /usr/local/go/gopath/pkg/mod: permission denied”
terms of settlement :
First execute the following command to create mod, Re execute the module installation command
sudo mkdir /usr/local/go/gopath/pkg/modgo Dependency package management
【 Update third-party dependencies 】
go get -u github.com/xuri/excelize/v2【 Use go modules】
sudo mkdir /usr/local/go/gopath/pkg/modgo mod It is the official package management tool , Before, there were unofficial package management tools , for example :go vendor Tools such as
development history
stay go1.11 After the version ,go mod It is designated as the official package management tool , It provides more flexible management , The package can be versioned , And your project doesn't have to be GOPATH I'm off .
stay Go 1.14 in , Module support is considered ready for production , And encourage all users to migrate from other dependency management systems to modules .
It is recommended to use Go 1.15 And later versions
Using Go Modules - The Go Programming Language
Preparations before use
set GO111MODULE=onEnvironment variables can be used GO111MODULE Turn module support on or off , It has three optional values :off、on、auto, The default value is auto.
GO111MODULE=off No module support ,go From GOPATH and vendor Folder search package .
GO111MODULE=on Module support ,go Will ignore GOPATH and vendor Folder , Based on go.mod Download dependency .
GO111MODULE=auto stay $GOPATH/src Outside and the root directory has go.mod When you file , Enable module support .
When using modules ,GOPATH It's meaningless , But it still stores the download dependency in the GOPATH/pkg/mod in , Will also put goinstall The results of GOPATH/bin in
set GOPRIVATE=XXX.XXX.comThis command is when using proxy , Filter GOPRIVATE Download the package under the set domain name , Usually private library
The command is Go 1.13 New features in version
set GOPROXY=https://goproxy.cn
This command sets the proxy , To prevent from being qiang, Set on demand
There are other agents such as ,https://goproxy.io;http://mirrors.aliyun.com/goproxy/
Go Mod command
download download modules to local cache ( Download dependent module To local cache))
edit edit go.mod from tools or scripts ( edit go.mod file )
graph print module requirement graph ( Print module dependency graph ))
init initialize new module in current directory ( Initialize a new one under the current folder module, establish go.mod file ))
tidy add missing and remove unused modules ( Add lost module, Remove unused module)
vendor make vendored copy of dependencies ( Copy dependency to vendor Next )
verify verify dependencies have expected content ( Verification dependency )
why explain why packages or modules are needed ( Explain why you need to rely )Practice
1. perform go mod init
go mod init demoAfter two sentences of command , You'll see , There are many projects go.mod and go.sum file .
go.mod: It can be understood as package management file
go.sum: It can be understood as the version control file of the package
To be more precise ,go.sum Is a build status trace file

Be careful :

2. go mod tidy
go mod tidyUse go mod after , After the package is downloaded, it is put in $GOPATH/pkg/mod Next

Reference documents :
https://blog.csdn.net/benben_2015/article/details/82227338
https://blog.csdn.net/wangyufeng43400141/article/details/107170481/
边栏推荐
- ArcGIS应用(二十二)Arcmap加载激光雷达las格式数据
- Four essential material websites for we media people to help you easily create popular models
- Awk from entry to earth (14) awk output redirection
- Awk from entry to earth (7) conditional statements
- Bishi blog (13) -- oral arithmetic test app
- China electronic grade sulfur trioxide Market Forecast and investment strategy report (2022 Edition)
- Codeforces Global Round 21(A-E)
- [Chongqing Guangdong education] National Open University spring 2019 455 logistics practice reference questions
- Ehrlich sieve + Euler sieve + interval sieve
- 2022 gas examination registration and free gas examination questions
猜你喜欢

Getting started with microservices: gateway gateway

Snipaste convenient screenshot software, which can be copied on the screen
](/img/3f/4d8f4c77d9fde5dd3f53ef890ecfa8.png)
C语言-入门-基础-语法-[运算符,类型转换](六)

Awk from entry to earth (12) awk can also write scripts to replace the shell

Go zero micro service practical series (IX. ultimate optimization of seckill performance)

C语言-入门-基础-语法-数据类型(四)

Codeforces Round #750 (Div. 2)(A,B,C,D,F1)
![[attack and defense world | WP] cat](/img/01/c5cacfdcca511d4b523611abca6eef.jpg)
[attack and defense world | WP] cat

Clion console output Chinese garbled code

Codeforces Round #803 (Div. 2)(A-D)
随机推荐
ArcGIS application (XXII) ArcMap loading lidar Las format data
C language - Introduction - Foundation - syntax - [variable, constant light, scope] (V)
[untitled] forwarding least square method
如何通过antd的upload控件,将图片以文件流的形式发送给服务器
What exactly is DAAS data as a service? Don't be misled by other DAAS concepts
Talk about single case mode
From scratch, use Jenkins to build and publish pipeline pipeline project
awk从入土到入门(10)awk内置函数
Call Baidu map to display the current position
[untitled] 2022 polymerization process analysis and polymerization process simulation examination
Manjaro install wechat
FRP intranet penetration, reverse proxy
Awk from entry to earth (12) awk can also write scripts to replace the shell
C语言-入门-基础-语法-[变量,常亮,作用域](五)
Codeforces Round #793 (Div. 2)(A-D)
C language - Introduction - Foundation - syntax - [main function, header file] (II)
Awk from entry to earth (18) GAW K line manual
What if the wireless network connection of the laptop is unavailable
Sequence model
Industry depression has the advantages of industry depression