SettingGOPATH
Pages 133
- Home
- Articles
- Benchmarks
- Blogs
- Books
- BoundingResourceUse
- cgo
- ChromeOS
- CodeReview
- CodeReviewComments
- CodeTools
- Comments
- CommitMessage
- CommonMistakes
- CompilerOptimizations
- Conferences
- CoreDumpDebugging
- Courses
- CustomPprofProfiles
- Darwin
- DashboardBuilders
- DesignDocuments
- DevExp
- Diagnostics
- DragonFly BSD
- Errors
- ExperienceReports
- FileTreeDocumentation
- FreeBSD
- FromXToGo
- Gardening
- GccgoCrossCompilation
- GcToolchainTricks
- GerritAccess
- GerritBot
- GithubAccess
- GitHubCodeLayout
- Go 1.10 Release Party
- Go 1.6 release party
- Go 1.8 Release Party
- Go Release Cycle
- Go1point1Gotchas
- GoArm
- GoForCPPProgrammers
- GoGenerateTools
- GoGetProxyConfig
- GoGetTools
- Gomote
- GOPATH
- Gopher
- GoStrings
- GoTalks
- GoUserGroups
- GoUsers
- GoVsGenerics
- HandlingIssues
- Hashing
- heapdump13
- heapdump14
- heapdump15
- HostedContinuousIntegration
- How to ask for help
- HowToAsk
- HttpFetch
- HttpStaticFiles
- IDEsAndTextEditorPlugins
- InstallFromSource
- InstallTroubleshooting
- InterfaceSlice
- InvalidFlag
- Iota
- IssueLabels
- Learn
- LearnConcurrency
- LearnErrorHandling
- LearnServerProgramming
- LearnTesting
- Linux
- LockOSThread
- MethodSets
- MinimumRequirements
- Mobile
- MultipleGoRoots
- MutexOrChannel
- NativeClient
- NetBSD
- NewSpeakers
- NoMeToo
- NonEnglish
- OlderVersions
- OpenBSD
- PackageManagementTools
- PackagePublishing
- PanicAndRecover
- PerfDashboard
- Performance
- Plan9
- Podcasts
- PortingPolicy
- PriorDiscussion
- Projects
- ProviderIntegration
- Questions
- RaceDetector
- Range
- RateLimiting
- Rationales
- ResearchPapers
- Screencasts
- SendingMail
- SettingGOPATH
- SignalHandling
- SimultaneousAssignment
- SliceTricks
- Solaris
- SQLDrivers
- SQLInterface
- Style
- SubRepositories
- SuccessStories
- Switch
- TableDrivenTests
- Timeouts
- Training
- Ubuntu
- vgo
- WebAccessibilityResourcesAndTips
- Well known struct tags
- WhyGo
- Windows
- WindowsBuild
- WindowsCrossCompiling
- WindowsDLLs
- Show 118 more pages…
Clone this wiki locally
The GOPATH environment variable specifies the location of your workspace. If no GOPATH is set, it is assumed to be $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 environment variable. This page explains how to set this variable on various platforms.
Unix systems
GOPATH
can be any directory on your system. In Unix examples, we will set it to $HOME/go
(since Go 1.8, it's a default GOPATH
on Unix-like systems). Note that GOPATH
must not be the same path as your Go installation. Another common setup is to set GOPATH=$HOME.
Bash
Edit your ~/.bash_profile
to add the following line:
export GOPATH=$HOME/go
Save and exit your editor. Then, source your ~/.bash_profile
.
source ~/.bash_profile
Note: Set the GOBIN path to generate a binary file when
go install
is run.export GOBIN=$HOME/go/bin
Zsh
Edit your ~/.zshrc
file to add the following line:
export GOPATH=$HOME/go
Save and exit your editor. Then, source your ~/.zshrc
.
$ source ~/.zshrc
fish
set -x -U GOPATH $HOME/go
The
-x
is used to specify that this variable should be exported and the-U
makes this a universal variable, available to all sessions and persistent
To set the GOBIN path:
set -x -U GOBIN $GOPATH/bin
Windows
Your workspace can be located wherever you like,
but we'll use C:\go-work
in this example.
NOTE: that GOPATH
must not be the same path as your Go installation.
- Create folder at
C:\go-work
. - Right click on "Start" and click on "Control Panel". Select "System and Security", then click on "System".
- From the menu on the left, select the "Advanced systems settings".
- Click the "Environment Variables" button at the bottom.
- Click "New" from the "User variables" section.
- Type
GOPATH
into the "Variable name" field. - Type
C:\go-work
into the "Variable value" field. - Click OK.
Windows 10
There is a faster way to edit Environment Variables
with search
- Left click on "Search" and type
env
orenvironment
. selectEdit environment variables for your account
- and follow step above