Home >Backend Development >Golang >How to Fix the 'Package Not in GOROOT' Error When Using Go Modules?
Resolving "Package Not in GOROOT" Error for Go Modules
A common issue encountered when working with Go modules is receiving the error message "package [package name] is not in GOROOT." This error is generally caused by improper configuration of environment variables.
Solution
To resolve this error, ensure that the following environment variables are correctly set:
Configuration in Bash
In the .bashrc file, add the following lines:
export GO111MODULE=on export GOPATH=/path/to/workspace export PATH=$PATH:$GOPATH/bin:$GOROOT/bin export GOROOT=/path/to/GOROOT
After Configuration
After setting the environment variables, source the .bashrc file to load the changes.
source ~/.bashrc
Go Module Workflow
To use Go modules, follow these steps:
By following these steps and ensuring proper environment configuration, the "package not in GOROOT" error can be resolved.
The above is the detailed content of How to Fix the 'Package Not in GOROOT' Error When Using Go Modules?. For more information, please follow other related articles on the PHP Chinese website!