swaggo / gin-swagger

gin middleware to automatically generate RESTful API documentation with Swagger 2.0.
MIT License
3.66k stars 266 forks source link

zsh: command not found: swag #287

Closed agn-7 closed 8 months ago

agn-7 commented 9 months ago

I installed gin-swagger but I cannot run the command swag init!

What am I wrong?

agn-7 commented 8 months ago

I tried both with go get -u github.com/swaggo/swag/cmd/swag and go install github.com/swaggo/swag/cmd/swag@latest without any success

agn-7 commented 8 months ago

I realized the problem was related to the GOPATH!

I went through the ~/go/bin path and saw the swag there indicating it is installed properly. Then, I opened the .zshrc file to check the variables which were as follows:

GOROOT=/usr/local/go
GOPATH=~/.go
PATH=$PATH:$GOROOT/bin:$GOPATH/bin

Next, I rectified the GOPATH from GOPATH=~/.go to GOPATH=~/go to solve the issue.

Now, swag init works.