Home >Backend Development >Golang >Why Does `go install` Ignore GOPATH and Install in `/usr/lib/go`?

Why Does `go install` Ignore GOPATH and Install in `/usr/lib/go`?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-31 08:39:02538browse

Why Does `go install` Ignore GOPATH and Install in `/usr/lib/go`?

go install Attempts to Use GOROOT despite Set GOPATH

Original Issue:

The user encountered an issue where go install attempted to install packages in /usr/lib/go instead of the intended directory /home/me/dev/go, despite the GOPATH being set in .profile.

Troubleshooting and Solution:

After investigating further, it was discovered that the issue resolved itself after upgrading to Go 1.1beta2. However, the exact cause of the problem remains unknown.

Best Practices for GOPATH Setup:

To ensure proper GOPATH configuration, follow these best practices:

  • Set GOPATH in .profile as export GOPATH=/home/me/dev/go.
  • Create the following directories under GOPATH:

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

    export PATH=$PATH:$HOME/dev/go/bin
  • After logging in, run the following commands to verify the GOPATH setup:

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

Note:

The issue described in the original question may have been a transient error that was resolved with the Go update. However, following these best practices can help avoid similar problems in the future.

The above is the detailed content of Why Does `go install` Ignore GOPATH and Install in `/usr/lib/go`?. 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