Download package using "go get"

Asked

Viewed 107 times

0

The installation of go in /usr/local/go occurs perfectly and I can verify this using:

go --version

When trying to use get with:

go get github.com/russross/blackfriday

I get the following error:

package github.com/russross/Blackfriday: mkdir /usr/local/go/bin/go: not a directory

Detro of use/local/go/bin/... the go is actually the file that runs the language for this reason I cannot create a folder in this same path.

return of go env

GOARCH="386"
GOBIN=""
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/usr/local/go/bin/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_386"
GCCGO="gccgo"
GO386="sse2"
CC="gcc"
GOGCCFLAGS="-fPIC -m32 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build009583842=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
  • Did you ever see that question on Soen ? seems to be the same problem https://stackoverflow.com/questions/15846914/go-install-always-attempts-to-use-goroot-and-gopath-is-not-listed-under-go-env

  • the question inSOen this with a different error to what I quoted, even if I apply the solution proposed in the post I get the error GOPATH entry is relative; must be absolute path: "".

1 answer

0

I believe the problem is your environment variable GOPATH, to GOROOT seems to be right.

You should point the variable to the directory you want to be your Workspace.

Here, for example, is configured like this:

$ go env
GOARCH="386"
GOBIN=""
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/admin/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_386"
GCCGO="gccgo"
GO386=""
CC="gcc"
GOGCCFLAGS="-fPIC -m32 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build890319421=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

The environment variable GOROOT points to the installation files:

$ ls -la $GOROOT
total 168
drwxr-xr-x 11 root root   4096 May 24 18:16 .
drwxrwsr-x 11 root staff  4096 May 30 10:48 ..
drwxr-xr-x  2 root root   4096 May 24 18:15 api
-rw-r--r--  1 root root  33243 May 24 18:15 AUTHORS
drwxr-xr-x  2 root root   4096 Aug  8 09:36 bin
drwxr-xr-x  4 root root   4096 May 24 18:16 blog
-rw-r--r--  1 root root   1366 May 24 18:15 CONTRIBUTING.md
-rw-r--r--  1 root root  45710 May 24 18:15 CONTRIBUTORS
drwxr-xr-x  8 root root   4096 May 24 18:15 doc
-rw-r--r--  1 root root   5686 May 24 18:15 favicon.ico
drwxr-xr-x  3 root root   4096 May 24 18:15 lib
-rw-r--r--  1 root root   1479 May 24 18:15 LICENSE
drwxr-xr-x 14 root root   4096 May 24 18:16 misc
-rw-r--r--  1 root root   1303 May 24 18:15 PATENTS
drwxr-xr-x  6 root root   4096 May 24 18:16 pkg
-rw-r--r--  1 root root   1399 May 24 18:15 README.md
-rw-r--r--  1 root root     26 May 24 18:15 robots.txt
drwxr-xr-x 46 root root   4096 May 24 18:15 src
drwxr-xr-x 17 root root  12288 May 24 18:15 test
-rw-r--r--  1 root root      7 May 24 18:15 VERSION

And the environment variable GOPATH points to where my Workspace is:

$ ls -la $GOPATH
total 20
drwxr-xr-x 5 admin admin 4096 Aug  7 20:10 .
drwxr-xr-x 7 admin admin 4096 Sep 15 07:00 ..
drwxr-xr-x 2 admin admin 4096 Aug 16 02:11 bin
drwxr-xr-x 3 admin admin 4096 Aug  7 20:10 pkg
drwxr-xr-x 8 admin admin 4096 Aug  7 21:55 src

Just create the folder src and put your source code in there, the rest of the folders are usually created as you compile code with the go build.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.