Why Is go install Installing to GOROOT Instead of GOPATH?

Linda Hamilton
Release: 2024-11-02 05:08:02
Original
695 people have browsed it

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
    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. Source the profile file:

    source $HOME/.profile
    Copy after login
  4. Verify the settings:

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

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!