kim yongbin | 234fa29 | 2017-01-09 22:48:13 +0900 | [diff] [blame] | 1 | The GOPATH environment variable specifies the location of your workspace. By default it is `$HOME/go` on Unix systems and `%USERPROFILE%\go` on Windows. If you want to use a custom location as your workspace, you can set the GOPATH env variable. This page explains how to set this variable on various platforms. |
jbd@ | 8858ce6 | 2017-01-06 17:21:05 -0800 | [diff] [blame] | 2 | |
| 3 | |
jbd@ | 479e84a | 2017-01-06 17:18:01 -0800 | [diff] [blame] | 4 | - [Unix systems](#unix-systems) |
| 5 | * [Bash](#bash) |
| 6 | * [Zsh](#zsh) |
| 7 | - [Windows](#windows) |
| 8 | |
jbd@ | fab8831 | 2017-01-06 17:17:16 -0800 | [diff] [blame] | 9 | # Unix systems |
jbd@ | bc4124e | 2017-01-05 23:28:35 -0800 | [diff] [blame] | 10 | |
jbd@ | c03fd47 | 2017-01-05 23:36:55 -0800 | [diff] [blame] | 11 | `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] | 12 | |
jbd@ | fab8831 | 2017-01-06 17:17:16 -0800 | [diff] [blame] | 13 | ## Bash |
jbd@ | bc4124e | 2017-01-05 23:28:35 -0800 | [diff] [blame] | 14 | |
| 15 | Edit your `.bash_profile` to add the following line: |
| 16 | ```bash |
| 17 | export GOPATH=$HOME/work |
| 18 | ``` |
| 19 | |
jbd@ | 164ffea | 2017-01-05 23:31:00 -0800 | [diff] [blame] | 20 | Save and exit your editor. Then, source your `~/.bash_profile`. |
jbd@ | bc4124e | 2017-01-05 23:28:35 -0800 | [diff] [blame] | 21 | ```bash |
| 22 | $ source ~/.bash_profile |
| 23 | ``` |
| 24 | |
jbd@ | fab8831 | 2017-01-06 17:17:16 -0800 | [diff] [blame] | 25 | ## Zsh |
jbd@ | 164ffea | 2017-01-05 23:31:00 -0800 | [diff] [blame] | 26 | |
| 27 | Edit `~/.zshrc` file to add the following line: |
| 28 | |
| 29 | ```bash |
| 30 | export GOPATH=$HOME/work |
| 31 | ``` |
| 32 | Save and exit your editor. Then, source your `~/.zshrc`. |
| 33 | ```bash |
| 34 | $ source ~/.zshrc |
| 35 | ``` |
| 36 | |
jbd@ | fab8831 | 2017-01-06 17:17:16 -0800 | [diff] [blame] | 37 | # Windows |
jbd@ | bc4124e | 2017-01-05 23:28:35 -0800 | [diff] [blame] | 38 | |
| 39 | Your workspace can be located wherever you like, |
| 40 | but we'll use `C:\work` in this example. |
jbd@ | c03fd47 | 2017-01-05 23:36:55 -0800 | [diff] [blame] | 41 | Note that `GOPATH` must not be the same path as your Go installation. |
jbd@ | bc4124e | 2017-01-05 23:28:35 -0800 | [diff] [blame] | 42 | |
| 43 | * Create folder at `C:\work`. |
| 44 | * Right click on "Start" and click on "Control Panel". Select "System and Security", then click on "System". |
| 45 | * From the menu on the left, select the "Advanced systems settings". |
| 46 | * Click the "Environment Variables button at the bottom. |
| 47 | * Click "New" from the "User variables" section. |
| 48 | * Type `GOPATH` into the "Variable name" field. |
| 49 | * Type `C:\work` into the "Variable value" field. |
| 50 | * Click OK. |
| 51 | |
jbd@ | bc4124e | 2017-01-05 23:28:35 -0800 | [diff] [blame] | 52 | |