Search code examples
goswaggeropenapigo-gingin-swagger

zsh: command not found: swag


I'm struggling with gin-swagger to set OpenAPI documentation on several APIs written in gin. While I installed the package in the project route via go install github.com/swaggo/swag/cmd/swag@latest I am not able to run the swag init!

swag init

Out:

zsh: command not found: swag

Here's the repo link.


Solution

  • 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.