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
Release: 2024-10-31 08:39:02
Original
519 people have browsed it

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
    Copy after login
  • Add the following lines to .profile:

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

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

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!

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