Setting GOPATH
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 (the default since Go 1.8). Note that GOPATH must not be the same path as your Go installation. Another common setup is to set GOPATH=$HOME.
Go 1.13+
go env -w GOPATH=$HOME/go
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
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.
Windows
Your workspace can be located wherever you like,
but we'll use C:\go-work in this example.
NOTE: GOPATH must not be the same path as your Go installation.
- Create a 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 system settings".
- Click the "Environment Variables" button at the bottom.
- Click "New" from the "User variables" section.
- Type
GOPATHinto the "Variable name" field. - Type
C:\go-workinto the "Variable value" field. - Click OK.
Go 1.13+ (command line)
- Open a command prompt (
Win+rthen typecmd) or a powershell window (Win+i). - Type
go env -w GOPATH=c:\go-work.
Windows 10 (GUI)
There is a faster way to edit Environment Variables via search:
- Left click on "Search" and type
envorenvironment. - Select "Edit environment variables for your account".
- ... and follow steps above.
Windows 10 (command line)
- Open a command prompt (
Win+rthen typecmd) or a powershell window (Win+i). - Type
setx GOPATH %USERPROFILE%\go. (This will set theGOPATHto your[home folder]\go, such asC:\Users\yourusername\go.) - Close the command or PowerShell window. (The environment variable is only available for new command or PowerShell windows, not for the current window.)
AVX512 Articles AssemblyPolicy Benchmarks Blogs Books BoundingResourceUse CSSStyleGuide ChromeOS CodeReview CodeReviewComments CodeReviewConcurrency CodeTools Comments CommitMessage CommonMistakes CompilerOptimizations Conferences Configuring GoLand for WebAssembly Contributing to gopls CoreDumpDebugging Courses CreatingSubRepository CustomPprofProfiles Darwin DashboardBuilders Deprecated DesignDocuments Diagnostics Download build farm failed logs and debugging DragonFly BSD ErrorValueFAQ Errors ExperienceReports FileTreeDocumentation FreeBSD FromXToGo Frozen Fuzzing trophy case GOPATH Gardening GcToolchainTricks GccgoCrossCompilation GerritAccess GerritBot GithubAccess Go 1.10 Release Party Go 1.6 release party Go 1.8 Release Party Go Community Slides Go Release Cycle Go2 Go2ErrorHandlingFeedback Go2ErrorValuesFeedback Go2GenericsFeedback GoArm GoForCPPProgrammers GoGenerateTools GoGetProxyConfig GoGetTools GoMips GoStrings GoTalks GoUserGroups GoUsers Gomote Gopher HandlingIssues Home HostedContinuousIntegration How to ask for help HowToAsk IDEsAndTextEditorPlugins InstallFromSource InstallTroubleshooting InterfaceSlice InvalidFlag Iota Learn LearnConcurrency LearnErrorHandling LearnServerProgramming LearnTesting Linux LinuxKernelSignalVectorBug Livestreams LockOSThread MacOS12BSDThreadRegisterIssue MethodSets MinimumRequirements MinorReleases Mobile Modules MutexOrChannel NativeClient NetBSD NewSpeakers NoMeToo NoPlusOne NonEnglish OpenBSD PackagePublishing PanicAndRecover PerfDashboard Performance Plan9 Podcasts PortingPolicy PriorDiscussion Projects Proposals ProviderIntegration Questions Quiet Weeks Range RateLimiting ResearchPapers Resolving Problems From Modified Module Path Resources for slog SQLDrivers SQLInterface Screencasts SettingGOPATH SignalHandling SimultaneousAssignment SliceTricks SlowBots Solaris Spectre Spelling Style SuccessStories Switch TableDrivenTests TargetSpecific TestComments TestFailures Timeouts Training Ubuntu Watchflakes WebAccessibilityResourcesAndTips Well known struct tags WhyGo Windows WindowsBuild WindowsCrossCompiling WindowsDLLs X Repositories _Footer cgo golang tools gopherbot gopls integrator FAQ gopls heapdump13 heapdump14 heapdump15 through heapdump17 heapdump15