Home > Backend Development > Golang > Why Does `go install` Ignore My `GOPATH` Setting and Install to `GOROOT`?

Why Does `go install` Ignore My `GOPATH` Setting and Install to `GOROOT`?

Barbara Streisand
Release: 2024-10-31 10:47:02
Original
847 people have browsed it

Why Does `go install` Ignore My `GOPATH` Setting and Install to `GOROOT`?

go install Defaulting to GOROOT when GOPATH is Set

In an encounter with a perplexing issue, a user discovered that go install persisted in using GOROOT as the installation destination, neglecting the set GOPATH.

Upon investigating, it emerged that despite the environment variable $GOPATH being set to /home/me/dev/go, go env failed to recognize it. This anomaly caused go install to attempt installing packages in /usr/lib/go.

The user's initial attempts of setting $GOPATH in ~/.profile and sourcing it proved futile. However, the problem mysteriously resolved after upgrading to Go 1.1beta2.

To provide a possible solution, it is essential to establish the GOPATH workspace. The following steps outline the process:

  1. Create directories for source code and binaries:

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

    export GOPATH=$HOME/dev/go:
    export PATH=$PATH:$HOME/dev/go/bin
    Copy after login
  3. Reboot or log out and back in.
  4. Immediately after logging in, verify the settings:

    env | grep -i '^GO'
    Copy after login

This process establishes a custom workspace for Go. If GOPATH is still not recognized, post the output of the supplied commands for further assistance.

The above is the detailed content of Why Does `go install` Ignore My `GOPATH` Setting and Install to `GOROOT`?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template