Go: go get $ GOPATH error when GOPATH is set

When you run the get get command:

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

I get the following error

package github.com/go-sql-driver/mysql: unable to load, do not set $ GOPATH. For more information see: go help gopath

However, $ GOPATH is already installed.

Launch echo $GOPATHgives/Users/userxyz/Desktop/Code

Launch go envgives

.....

GOPATH="/Users/userxyz/Desktop/Code"

...

GOROOT="/usr/local/go"

.....

I already tried setting GOPATH as an environment variable by adding the following lines

export GOPATH="$HOME/Desktop/Code"
export PATH=$PATH:$GOPATH/bin

to the following files, alternatively

~/.profile (/etc/profile)
~/.bashrc
~/.bash_profile
+4
source share
5 answers
sudo go get github.com/go-sql-driver/mysql

This is done go getunder a rootuser who does not $GOPATH.

Just do:

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

Usually do:

go get

, . , :

go get -t
+5

sudo. . sudo go env, , GOPATH

+3

sudo. " Xcode/iOS " , Xcode Xcode.

0

, , 4 , , , ...

, , sudo root. $go get , , sudo, GOPATH unset. , , .

export GOPATH=/directory/of/your/goproject
chown -R ubuntu@staff $GOPATH
cd $GOPATH && go get 

env :

export GOPATH=/home/ubuntu/work export
PATH=$PATH:$GOROOT/bin:$GOPATH/bin

, $GOROOT.


, [profile.d] [1] env:

cat > /etc/profile.d/setgoenv.sh <<EOL
export GOPATH=/home/ubuntu/work
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
EOL

, .

0

GOPATH, , GOROOT PATH

export GOROOT=/opt/go, export GOPATH=$HOME/work, , $HOME/work , , , go get {whattoget}, export GOPATH=$HOME/work export PATH=$PATH:$GOROOT/bin:$GOPATH/bin ~/.profile. .

Go ahead, I could just start using Docker to create my go projects, as this is a bit of a pain, and the documentation and errors are long, but do not seem to explain what is wrong in any meaningful and understandable way ( GOROOTand GOPATHwere installed, but PATH GOROOTalso GOPATHeverything seemed to be off a bit).

0
source

Source: https://habr.com/ru/post/1548625/


All Articles