Skip to content

Instantly share code, notes, and snippets.

@molivier
Last active January 3, 2024 09:57
Show Gist options
  • Star 61 You must be signed in to star a gist
  • Fork 17 You must be signed in to fork a gist
  • Save molivier/271bba5d67de1583a8e3 to your computer and use it in GitHub Desktop.
Save molivier/271bba5d67de1583a8e3 to your computer and use it in GitHub Desktop.
Set $GOPATH on Mac OSX : bash_profile
# Edit ~/.bash_profile
export GOPATH=/Users/$USER/go
export PATH=$GOPATH/bin:$PATH
# Reload profile : source ~/.bash_profile
@ritzeng
Copy link

ritzeng commented Oct 5, 2018

ok, but is that to place into a file or must i run that all the time ?
Sometime s the UNIC guys do not start at the basics.

@PabloThiele
Copy link

PabloThiele commented Jan 17, 2019

ok, but is that to place into a file or must i run that all the time ?
Sometime s the UNIC guys do not start at the basics.

Adding this on your bash_profile will solve the problem. It's not necessary to do it by yourself.

Since:
bash_profile is a configuration file for bash shell. When bash is invoked as an interactive login shell it first reads and executes commands from ~/.bash_profile. E.g. This file can be used to export variables in shell. You can put your variables in ~/.bashrc also apart from bash profile

If in your case still not work, verify if you're really using bash or other shells scripts.
You can do this typing the command:
ps -p $$
This will provide the actual shell name.
In my case is:
PID TTY TIME CMD
790 ttys000 0:00.59 -zsh

So I'm using zsh as shell for instance I need to add any related configuration to my ~/.zshrc file instead.

@dkatzsos
Copy link

Change this

export GOPATH=/Users/username/go

into this

export GOPATH=/Users/$USER/go

@molivier
Copy link
Author

@dkatzsos Good catch! Gist updated.

@elacy
Copy link

elacy commented May 8, 2020

or you could do $HOME/go and then it would work if you are sharing your rc file between multiple systems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment