无法在本地安装golangci-lint。

huangapple go评论81阅读模式
英文:

Can't install golangci-lint locally

问题

我正在使用RHEL 8.6,我的Go版本如下:

$ go version
go version go1.18.3 linux/amd64

我正在尝试在本地安装golangci-lint,但是文档中描述的方法都不起作用。

我尝试了以下方法:

第一种方法:

$ curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.46.2
golangci/golangci-lint info checking GitHub for tag 'v1.46.2'
golangci/golangci-lint info found version: 1.46.2 for v1.46.2/linux/amd64
golangci/golangci-lint info installed /home/acabista/go/bin/golangci-lint
$ golangci-lint --version
bash: golangci-lint: command not found...

第二种方法:

$ go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2
$ golangci-lint --version
bash: golangci-lint: command not found...

我是否漏掉了某个步骤?如何使本地安装生效?

英文:

I'm using RHEL 8.6 and my Go version is the following:

$ go version
go version go1.18.3 linux/amd64

I'm trying to install locally golangci-lint and none of the described ways in the documentation are working.

What I tried:

First:

$ curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.46.2
golangci/golangci-lint info checking GitHub for tag 'v1.46.2'
golangci/golangci-lint info found version: 1.46.2 for v1.46.2/linux/amd64
golangci/golangci-lint info installed /home/acabista/go/bin/golangci-lint
$ golangci-lint --version
bash: golangci-lint: command not found...

Second:

$ go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2
$ golangci-lint --version
bash: golangci-lint: command not found...

Am I missing a step? How can I make this local installation work?

答案1

得分: 6

如果golang-ci已经正确安装,问题很可能是安装目录没有添加到您的PATH环境变量中。调用golang-ci的方式应该是这样的:

${GOPATH}/bin/golangci-lint --version

或者

/home/acabista/go/bin/golangci-lint --version

要确切了解发生了什么,您可以检查GOPATH环境变量的内容。它的内容定义了在运行类似于go install的命令时二进制文件安装的位置。

echo $GOPATH

您还需要检查PATH变量的内容,它定义了shell在哪个目录中查找要执行的二进制文件:

echo $PATH
英文:

If golang-ci has properly been installed, the issue is most likely that the installation directory is not in your PATH environment variable. Calling golang-ci this way should then work:

${GOPATH}/bin/golangci-lint --version

or

/home/acabista/go/bin/golangci-lint --version

To chek what is happening exactly you can check the content of the GOPATH environment variable. Its content defines where binaries are installed when a go install like command is run.

echo $GOPATH

You need to check also what is the content of the PATH variable, this one defines in which directory the shell looks for binary to execute:

echo $PATH

答案2

得分: 0

按照以下方式安装以避免错误:

curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b $(go env GOPATH)/bin v1.54.0
英文:

Install it this way to avoid error

curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b $(go env GOPATH)/bin v1.54.0

huangapple
  • 本文由 发表于 2022年7月8日 20:55:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/72911755.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定