jbd@ | bc4124e | 2017-01-05 23:28:35 -0800 | [diff] [blame] | 1 | # Environment Variables |
| 2 | |
| 3 | This page contains guides to set Go environment variables on various operating systems. |
| 4 | |
| 5 | ## Setting GOPATH |
| 6 | |
| 7 | ### Unix systems |
| 8 | |
jbd@ | c03fd47 | 2017-01-05 23:36:55 -0800 | [diff] [blame^] | 9 | `GOPATH` can be any directory on your system. In Unix examples, we will set it to `$HOME/work`. Note that `GOPATH` must not be the same path as your Go installation. Another common setup is to set GOPATH=$HOME. |
jbd@ | bc4124e | 2017-01-05 23:28:35 -0800 | [diff] [blame] | 10 | |
| 11 | #### Bash |
| 12 | |
| 13 | Edit your `.bash_profile` to add the following line: |
| 14 | ```bash |
| 15 | export GOPATH=$HOME/work |
| 16 | ``` |
| 17 | |
jbd@ | 164ffea | 2017-01-05 23:31:00 -0800 | [diff] [blame] | 18 | Save and exit your editor. Then, source your `~/.bash_profile`. |
jbd@ | bc4124e | 2017-01-05 23:28:35 -0800 | [diff] [blame] | 19 | ```bash |
| 20 | $ source ~/.bash_profile |
| 21 | ``` |
| 22 | |
jbd@ | edbf4f6 | 2017-01-05 23:31:18 -0800 | [diff] [blame] | 23 | #### Zsh |
jbd@ | 164ffea | 2017-01-05 23:31:00 -0800 | [diff] [blame] | 24 | |
| 25 | Edit `~/.zshrc` file to add the following line: |
| 26 | |
| 27 | ```bash |
| 28 | export GOPATH=$HOME/work |
| 29 | ``` |
| 30 | Save and exit your editor. Then, source your `~/.zshrc`. |
| 31 | ```bash |
| 32 | $ source ~/.zshrc |
| 33 | ``` |
| 34 | |
jbd@ | bc4124e | 2017-01-05 23:28:35 -0800 | [diff] [blame] | 35 | ### Windows |
| 36 | |
| 37 | Your workspace can be located wherever you like, |
| 38 | but we'll use `C:\work` in this example. |
jbd@ | c03fd47 | 2017-01-05 23:36:55 -0800 | [diff] [blame^] | 39 | Note that `GOPATH` must not be the same path as your Go installation. |
jbd@ | bc4124e | 2017-01-05 23:28:35 -0800 | [diff] [blame] | 40 | |
| 41 | * Create folder at `C:\work`. |
| 42 | * Right click on "Start" and click on "Control Panel". Select "System and Security", then click on "System". |
| 43 | * From the menu on the left, select the "Advanced systems settings". |
| 44 | * Click the "Environment Variables button at the bottom. |
| 45 | * Click "New" from the "User variables" section. |
| 46 | * Type `GOPATH` into the "Variable name" field. |
| 47 | * Type `C:\work` into the "Variable value" field. |
| 48 | * Click OK. |
| 49 | |
jbd@ | bc4124e | 2017-01-05 23:28:35 -0800 | [diff] [blame] | 50 | |