0

When I set my GOPATH use:

set -gx GOPATH /usr/local/Cellar/go/1.8.1

I get this issue:

-bash: set: -g: invalid option
set: usage: set [--abefhkmnptuvxBCHP] [-o option] [arg ...]

qg_java_17137
  • 3,310
  • 10
  • 41
  • 84

2 Answers2

1

The bash command set doesn't support the g option. Also this command is not used for setting environment variables all together - your snippet is probably intended for a different shell (fishshell?).

In bash, use export as suggested:

export GOPATH /usr/local/Cellar/go/1.8.1

However, you should understand what you are doing and how to configure your environment on MacOS (guessing from 'Cellar' in your path).

This might be a good starting point.

Community
  • 1
  • 1
Jan Groth
  • 14,039
  • 5
  • 40
  • 55
-1

You should set GOROOT environment variable instead of GOPATH.

GOROOT should reference a folder (where go is installed), not the go executable itself

export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin 

GOPATH should reference a folder under which you will find src, pkg and bin. (it should not reference directly the src folder): See "How to Write Go Code - Workspace"

Regarding the GOPATH:

  • try and set it in your ~/.bashrc (using export).
  • check that your current shell is a bash (and not another one like fish)
  • check the output of go env.
Girdhar Sojitra
  • 648
  • 4
  • 14