英文:
Go: “no such file or directory” but it exists
问题
我安装了golang。
~/go/bin$ ls
go godoc gofmt
尝试测试,但无济于事。
~/go/bin$ go version
-bash: /home/orc/go/bin/go: 没有那个文件或目录
我的$PATH:
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/orc/go/bin:
信息:
~/go/bin$ uname -m
x86_64
~/go/bin$ file go
go: ELF 64-bit LSB 可执行文件,x86-64,版本 1 (SYSV),动态链接 (使用共享库),未剥离
~/go/bin$ pwd
/home/orc/go/bin
请告诉我出了什么问题?
更新:
~/go/bin$ ls -l
总用量 28688
-rwxr-xr-x 1 orc orc 9571864 2月 18 14:40 go
-rwxr-xr-x 1 orc orc 16164032 2月 18 14:41 godoc
-rwxr-xr-x 1 orc orc 3594712 2月 18 14:40 gofmt
~/go/bin$ ./go
-bash: ./go: 没有那个文件或目录
!!!
~/go/bin$ file $(which ls)
/bin/ls: ELF 32-bit LSB 可执行文件,Intel 80386,版本 1 (SYSV),动态链接 (使用共享库),适用于 GNU/Linux 2.6.18,已剥离
~/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
请解释如何修复它?
英文:
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?
答案1
得分: 17
你是否检查过你所安装的版本是否与你的架构相匹配?我刚刚在将一个32位二进制文件放在64位虚拟机上时遇到了完全相同的问题。我移除了32位版本,并安装了适合该架构的版本(根据网站上的说明),然后问题得到了解决。希望对你也有帮助。
英文:
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.
答案2
得分: 8
以下是翻译好的内容:
有几件事情需要检查,可能没有什么问题,但至少可以排除一些可能性:
-
你的问题中没有提到你当前的目录是否在
/home/orc
下,可以通过简单的pwd
命令来确认。 -
你能否直接运行该文件,比如使用
./go
或~/go/bin/go
命令? -
它是否可执行?可以通过
ls -l
命令来确认。 -
使用
uname -a
命令获取完整的机器详细信息。 -
检查系统可执行文件,以防它不是64位的,尽管有指示:
file $(which ls)
。 -
确保路径中没有奇怪的字符,可能会导致无法找到该文件:
echo $PATH | od -xcb
。 -
确保你的
GOPATH
设置正确(不确定这是否会影响go version
,但可以尝试一下)。
英文:
A couple of things to check, which may come to nothing, but they'll at least rule out things:
-
There's no indication in your question that your current directory is within
/home/orc
, a simplepwd
should clarify that. -
Can you run the file directly, such as with
./go
or~/go/bin/go
? -
Is it executable? The output of
ls -l
should clarify that. -
Get the full machine details with
uname -a
. -
Check the system executables in case it's somehow not 64-bit, despite the indication:
file $(which ls)
. -
Make sure there's no funny characters in the path that would prevent it being picked up there:
echo $PATH | od -xcb
. -
Make sure your
GOPATH
is set up correctly (not sure this would affectgo version
but it's something extra to try).
答案3
得分: 4
在我的情况下,Go编译器和语言没有被安装...
sudo apt install golang-go
英文:
In my case go compiler and language were not installed...
sudo apt install golang-go
答案4
得分: 1
对于我来说,这是答案,这是在Ubuntu 18.04的Windows子系统Linux 2上的安装步骤:
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
英文:
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
答案5
得分: 0
我在Docker中遇到了同样的问题,我正在为可能使用Docker的任何人编写答案。在我的情况下,我需要安装glibc
,为了提供背景信息,我正在使用alpine3.17
。
以下是我的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
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论