Home  >  Article  >  Backend Development  >  Why Is go install Installing to GOROOT Instead of GOPATH?

Why Is go install Installing to GOROOT Instead of GOPATH?

Linda Hamilton
Linda HamiltonOriginal
2024-11-02 05:08:02696browse

Why Is go install Installing to GOROOT Instead of GOPATH?

GOROOT Overriding GOPATH for go install

Problem

The $GOPATH variable is not being recognized by go env, and the go install command is attempting to install packages to the default GOROOT location (/usr/lib/go) instead of the intended GOPATH directory.

Cause

The issue may be related to an incorrect or improperly exported $GOPATH.

Solution

To resolve the issue, ensure that $GOPATH is set and exported correctly. Here are the steps to do so:

  1. Create the necessary directories within $GOPATH:

    mkdir -p $HOME/dev/go/src
    mkdir -p $HOME/dev/go/bin
  2. Add the following lines to $HOME/.profile:

    export GOPATH=$HOME/dev/go
    export PATH=$PATH:$HOME/dev/go/bin
  3. Source the profile file:

    source $HOME/.profile
  4. Verify the settings:

    env | grep -i '^GO'
    cat $HOME/.profile

You should see $GOPATH set to the correct directory /home/me/dev/go. If the issue persists after following these steps, consider upgrading to a newer version of Go, as the problem may have been resolved in a subsequent release.

The above is the detailed content of Why Is go install Installing to GOROOT Instead of GOPATH?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn