David Saintloth
David Saintloth

Reputation: 4231

package download fails , "GOPATH not set." why?

OS: Ubuntu 12.04

Go version reporting: 1.1.1

Action:

I have configured the .profile to contain the following lines:

export GOPATH="$HOME/workspace"

export PATH=$PATH:$GOPATH/bin

I have ensured that they are set in the go configuration by running "go env". However when I try to run the command, the screen reports as shown in the image below:

enter image description here

Possible constraining issues:

1) The box originally had Go v1.0 on it and I upgraded it to go version1.1.1, not sure that should mean anything...but if there is some twin configuration madness at work that may explain the fact it's not working despite the path being set.

2) I had the export commands in the .profile file but I see some threads indicate to put it in .bashrc, trying in either still gives the same problem.

Do I need to uninstall go 1.0 ? I just assumed version 1.1.1 would over ride it but that could be wrong. Ideally I wanted to uninstall go entirely and then install version 1.1.2 but I couldn't find anything at golang.org on uninstalling assuming that does solve the problem.

Thanks in advance for any assistance.

Upvotes: 1

Views: 1048

Answers (1)

Kyle Lemons
Kyle Lemons

Reputation: 4756

As the commenter above stated, you should not use sudo with go get. When you do, you have the root user's environment (which doesn't have your GOPATH) and any files or directories it creates won't be editable by your user. In the past, the go get command would not warn about not having a $GOPATH and so it was easier to get tripped up by this.

To fix your permissions, run the following command to change ownership back to your user:

sudo chown -R "$USER:" "$GOPATH"

You should only ever need to run a plain go get because you can (and should) set your $GOPATH to be a directory you can control. Be sure to read the How To Write Go Code and in particular its discusson on GOPATH.

Upvotes: 4

Related Questions