How do I SET the GOPATH environment variable on Ubuntu? What file must I edit?

前端 未结 25 3046
死守一世寂寞
死守一世寂寞 2020-11-28 00:45

I am trying to do a go get:

go get github.com/go-sql-driver/mysql

and it fails with the following error:

packa         


        
25条回答
  •  我在风中等你
    2020-11-28 01:02

    GOPATH is an environment variable to your work-space location. GOROOT is an environment variable to your installation directory. Although GOROOT and GOPATH is automatically set (if there would not be a bug) during the installation time, to specify it manually you can follow below process. Moreover, for more information you can refer to GO's wiki page.

    It is better to set GOPATH to a directory inside your home directory, e.g., $HOME/go, %USERPROFILE%\go (Windows).

    1. This is a solution mac, which is tested on macOS Sierra, ver. 10.12, and also in Gogland-EAP, which has been introduced as an IDE for Go programming by JetBrains.

    On your Terminal type

    vim ~/.profile
    

    in opened document on the Terminal press i and add the following path

    GOPATH=/path/to/a/directory/inside/home/directory
    GOROOT=/path/to/you/go/library
    PATH=$PATH:$GOPATH:$GOROOT:$GOROOT/bin
    

    press ESC and type :x. Lastly, you should restart (close and open) your terminal or Logout and Login again.

    1. For Windows and Linux configuration, please refer to Go wiki page at Githab on Setting GOPATH-Golang.

    CAUTION Do not set both GOROOT and GOPATH to the same directory, otherwise you will get a warning.

提交回复
热议问题