Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GOPATH environment variable not set

I'm trying to install the Oracle Driver for Go (go-oci8) following these instructions

The problem I'm facing is with the $GOPATH environment variable. When I execute the command:

sudo go get github.com/mattn/go-oci8

I get the error :

cannot download, $GOPATH not set. For more details see: go help gopath

However, I have the GOPATH properly set. My environment looks like this:

env | grep GO

GOARCH=amd64
GOROOT=/usr/local/go
GOOS=linux
GOPATH=/home/myuser/go/

ls $GOPATH
bin pkg src

I've found a similar post but the solution does not apply to my case.

like image 467
Jose Bagatelli Avatar asked Nov 08 '13 08:11

Jose Bagatelli


People also ask

How do I set Gopath variables?

To set GOPATH, open the bashrc/ bash_profle/zshrc file and type the following commands in it and then save the file. pkg − the directory that will contain the packages and shared object files if any. src − the directory where all the code you will write will be stored.

What is Gopath environment variable?

The GOPATH environment variable specifies the location of your workspace. It defaults to a directory named go inside your home directory, so $HOME/go on Unix, $home/go on Plan 9, and %USERPROFILE%\go (usually C:\Users\YourName\go ) on Windows.

How do I set the Gopath environment variable on Windows?

Adding GOPATH environment variableCreate a new folder in your C drive called "C:\Projects\Go". Open Run dialog by pressing win + r and type the sysdm. cpl ,3 inside the run dialog. And then click OK.

Do I need to set Gopath?

You don't need to set the GOPATH, it is set by default. The GOPATH directory is also named a workspace. Instead of randomly placing your code somewhere, you can use the gopath src directory. This is a mistake many beginners make, placing their code anywhere on the computer.


1 Answers

Sudo won't honor all your ENV variables for some very good security reasons.

The simplest way to fix this is /bin/env

sudo /bin/env GOPATH=/home/myuser/go go get <stuff>

But you don't need to do that, you really shouldn't need root to write to GOPATH, only GOROOT.

like image 140
Fred the Magic Wonder Dog Avatar answered Oct 05 '22 23:10

Fred the Magic Wonder Dog