user3514212
user3514212

Reputation: 151

Go: “no such file or directory” but it exists

I installed the golang.

~/go/bin$ ls
go  godoc  gofmt

Trying to test, but to no avail.

~/go/bin$ go version
-bash: /home/orc/go/bin/go: no such file or directory

My $PATH:

/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/orc/go/bin:

Info:

~/go/bin$ uname -m
x86_64

~/go/bin$ file go
go: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

~/go/bin$ pwd
/home/orc/go/bin

Please tell me what's wrong?

UPDATE

~/go/bin$ ls -l
итого 28688
-rwxr-xr-x 1 orc orc 9571864 Фев 18 14:40 go
-rwxr-xr-x 1 orc orc 16164032 Фев 18 14:41 godoc
-rwxr-xr-x 1 orc orc 3594712 Фев 18 14:40 gofmt

~/go/bin$ ./go
-bash: ./go: Нет такого файла или каталога

!!!

~/go/bin$ file $(which ls)
/bin/ls: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

~/go/bin$ uname -a
Linux olimp-web 2.6.32-5-amd64 #1 SMP Mon Jun 13 05:49:32 UTC 2011 x86_64 GNU/Linux

Please explain how to fix it?

Upvotes: 14

Views: 46778

Answers (5)

user18511546
user18511546

Reputation:

I was facing the same issue in Docker, I'm writing an answer for anybody that may be using docker, In my case I had to install glibc, for context I'm using alpine3.17

And here's the portion of my dockerfile -

COPY --from=golang:1.19.5-alpine3.17 /usr/local/go/ /usr/local/go/

ENV GOPATH=/go
ENV PATH="${PATH}:/usr/local/go/bin:$GOPATH/bin"

RUN apk update && apk add --no-cache wget gcompat && apk -U upgrade

RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
RUN wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r0/glibc-2.35-r0.apk
RUN apk add --force-overwrite glibc-2.35-r0.apk

Upvotes: 0

Pipo
Pipo

Reputation: 5073

In my case go compiler and language were not installed...

sudo apt install golang-go

Upvotes: 4

Joe Shakely
Joe Shakely

Reputation: 913

For me this was the answer, this is on ubuntu18.04 windows subsystem linux 2 install:

export GOPATH=$HOME/go

export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin

Upvotes: 4

paxdiablo
paxdiablo

Reputation: 881423

A couple of things to check, which may come to nothing, but they'll at least rule out things:

  1. There's no indication in your question that your current directory is within /home/orc, a simple pwd should clarify that.

  2. Can you run the file directly, such as with ./go or ~/go/bin/go?

  3. Is it executable? The output of ls -l should clarify that.

  4. Get the full machine details with uname -a.

  5. Check the system executables in case it's somehow not 64-bit, despite the indication: file $(which ls).

  6. Make sure there's no funny characters in the path that would prevent it being picked up there: echo $PATH | od -xcb.

  7. Make sure your GOPATH is set up correctly (not sure this would affect go version but it's something extra to try).

Upvotes: 8

PJeffes
PJeffes

Reputation: 376

Have you checked that you have the correct version for your architecture installed. I have just had this exact problem when I put a 32-bit binary on a 64-bit virtual machine. I removed the 32-bit version and installed the architecture appropriate version (based on the instructions on the website) and it worked. Hope that works for you too.

Upvotes: 17

Related Questions