Using Linux Amazon - Unable to Display "go version"

jng77

New Member
Joined
May 10, 2023
Messages
15
Reaction score
3
Credits
169
Dear Support,

I'm using Mac Terminal but connecting SSH with Linux Amazon (AWS), I successfully installed the latest Go language in Linux Amazon and I did update the $PATH to my "/.batch_profile" but was still unable to provide the go version. Kindly refer to the following copy-and-paste command line with its output:


[ec2-user@ip-172-31-22-105 ~]$ go version


-bash: go: command not found



[ec2-user@ip-172-31-22-105 ~]$ find ~ /usr/local -name go -type f -exec ls -ld {} \;

-rwxr-xr-x. 1 ec2-user ec2-user 15645180 Apr 26 15:35 /home/ec2-user/go/bin/go

-rwxr-xr-x. 1 root root 15645326 Mar 29 21:19 /usr/local/go/bin/go/bin/go

-rwxr-xr-x. 1 ec2-user ec2-user 15645180 Apr 26 15:35 /usr/local/go/go/bin/go


Note: I've posted the same question in the AWS Forum for 3 times and none of them were able to help me to solve it. That is why, I came here and I really need help.


Thanks.
 


What's the output of the following?
Code:
echo $PATH
 
Hi,

Here you are the result of echo $PATH

/home/ec2-user/bin:/usr/local/go/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/home/ec2-user/go/src/github.com/hyperledger/fabric-ca/bin:/usr/local/go/bin

What's the output of the following?
Code:
echo $PATH
 
It's because none of the directories where the actual go binary is located in is in your path. Which of those go binaries do you actually want to use since you have three of them in different locations. Also can you share the output of the following?
Code:
echo $SHELL
cat ~/.bashrc
cat ~/.bash_profile
 
It's because none of the directories where the actual go binary is located in is in your path. Which of those go binaries do you actually want to use since you have three of them in different locations. Also can you share the output of the following?
Code:
echo $SHELL
cat ~/.bashrc
cat ~/.bash_profile
Hi,

Sure. Here you are the following output of the Code above:

[ec2-user@ip-172-31-22-105 ~]$ echo $SHELL

/bin/bash

[ec2-user@ip-172-31-22-105 ~]$ cat ~/.bashrc

# .bashrc



# Source global definitions

if [ -f /etc/bashrc ]; then

. /etc/bashrc

fi



# User specific environment

if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]

then

PATH="$HOME/.local/bin:$HOME/bin:$PATH"

fi

export PATH



# Uncomment the following line if you don't like systemctl's auto-paging feature:

# export SYSTEMD_PAGER=



# User specific aliases and functions

if [ -d ~/.bashrc.d ]; then

for rc in ~/.bashrc.d/*; do

if [ -f "$rc" ]; then

. "$rc"

fi

done

fi



unset rc

[ec2-user@ip-172-31-22-105 ~]$ cat ~/.bash_profile

# .bash_profile



# Get the aliases and functions

if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi



# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin



# GOROOT is the location where Go package is installed on your system

export GOROOT=/usr/local/go



# GOPATH is the location of your work directory

export GOPATH=$HOME/go



# CASERVICEENDPOINT is the endpoint to reach your member's CA

# for example ca.m-K46ICRRXJRCGRNNS4ES4XUUS5A.n-MWY63ZJZU5HGNCMBQER7IN6OIU.managedblockchain.us-east-1.amazonaws.com:30002

export CASERVICEENDPOINT=MyMemberCaEndpoint



# ORDERER is the endpoint to reach your network's orderer

# for example orderer.n-MWY63ZJZU5HGNCMBQER7IN6OIU.managedblockchain.MyRegion.amazonaws.com:30001

export ORDERER=MyNetworkOrdererEndpoint



# Update PATH so that you can access the go binary system wide

export PATH=$GOROOT/bin:$PATH

export PATH=$PATH:/home/ec2-user/go/src/github.com/hyperledger/fabric-ca/bin



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

export PATH=$HOME/bin:$PATH
 
Which of these binaries do you actually want to use?
-rwxr-xr-x. 1 ec2-user ec2-user 15645180 Apr 26 15:35 /home/ec2-user/go/bin/go
-rwxr-xr-x. 1 root root 15645326 Mar 29 21:19 /usr/local/go/bin/go/bin/go
-rwxr-xr-x. 1 ec2-user ec2-user 15645180 Apr 26 15:35 /usr/local/go/go/bin/go
 
Which of these binaries do you actually want to use?
-rwxr-xr-x. 1 ec2-user ec2-user 15645180 Apr 26 15:35 /home/ec2-user/go/bin/go
-rwxr-xr-x. 1 root root 15645326 Mar 29 21:19 /usr/local/go/bin/go/bin/go
-rwxr-xr-x. 1 ec2-user ec2-user 15645180 Apr 26 15:35 /usr/local/go/go/bin/go
I would like to use this binary:

-rwxr-xr-x. 1 ec2-user ec2-user 15645180 Apr 26 15:35 /home/ec2-user/go/bin/go
 
Remove the following from ~/.bash_profile
Code:
 export GOROOT=/usr/local/go
 export GOPATH=$HOME/go
 export PATH=$GOROOT/bin:$PATH
 export PATH=$PATH:/home/ec2-user/go/src/github.com/hyperledger/fabric-ca/bin
 export PATH=$PATH:/usr/local/go/bin
 export PATH=$HOME/bin:$PATH
Than add the following.
Code:
export GOHOME=/home/ec2-user/go/bin
export PATH=$GOHOME:$PATH
The run the following.
Code:
source ~/.bash_profile
Share the output of the following.
Code:
which go
If the last command doesn't return anything, share the output of the following again.
Code:
echo $PATH
 
Remove the following from ~/.bash_profile
Code:
 export GOROOT=/usr/local/go
 export GOPATH=$HOME/go
 export PATH=$GOROOT/bin:$PATH
 export PATH=$PATH:/home/ec2-user/go/src/github.com/hyperledger/fabric-ca/bin
 export PATH=$PATH:/usr/local/go/bin
 export PATH=$HOME/bin:$PATH
Than add the following.
Code:
export GOHOME=/home/ec2-user/go/bin
export PATH=$GOHOME:$PATH
The run the following.
Code:
source ~/.bash_profile
Share the output of the following.
Code:
which go
If the last command doesn't return anything, share the output of the following again.
Code:
echo $PATH
Hi,

Thanks and have removed the following and added the code you provided. Here you are the Output:


[ec2-user@ip-172-31-22-105 ~]$ nano ~/.bash_profile

[ec2-user@ip-172-31-22-105 ~]$ source ~/.bash_profile

[ec2-user@ip-172-31-22-105 ~]$ which go

~/go/bin/go

[ec2-user@ip-172-31-22-105 ~]$ echo $PATH

/home/ec2-user/go/bin:/home/ec2-user/bin:/usr/local/go/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/home/ec2-user/go/src/github.com/hyperledger/fabric-ca/bin:/usr/local/go/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin


Additionally -->


[ec2-user@ip-172-31-22-105 ~]$ go version


-bash: /home/ec2-user/go/bin/go: cannot execute binary file: Exec format error


still unable to display the output of "go version"
 
[ec2-user@ip-172-31-22-105 ~]$ which go

~/go/bin/go

[ec2-user@ip-172-31-22-105 ~]$ echo $PATH

/home/ec2-user/go/bin:/home/ec2-user/bin:/usr/local/go/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/home/ec2-user/go/src/github.com/hyperledger/fabric-ca/bin:/usr/local/go/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin
This shows that it's using the go binary from you ~/go/bin/go directory now and not /home/ec2-user/go/bin/go.
Can you share the output of the following?
Code:
ls -l ~/go/bin
ls -l /home/ec2-user/go/bin
cat ~/.bash_profile
 
This shows that it's using the go binary from you ~/go/bin/go directory now and not /home/ec2-user/go/bin/go.
Can you share the output of the following?
Code:
ls -l ~/go/bin
ls -l /home/ec2-user/go/bin
cat ~/.bash_profile
Hi,

I see, is not reading from the /home/ec2-user/go/bin/go. Sure, definitely. Here you are the following Output:


[ec2-user@ip-172-31-22-105 ~]$ ls -1 ~/go/bin


go


gofmt



[ec2-user@ip-172-31-22-105 ~]$ ls -1 /home/ec2-user/go/bin


go


gofmt



[ec2-user@ip-172-31-22-105 ~]$ cat ~/.bash_profile


# .bash_profile





# Get the aliases and functions


if [ -f ~/.bashrc ]; then


. ~/.bashrc


fi





# User specific environment and startup programs


PATH=$PATH:$HOME/.local/bin:$HOME/bin








# CASERVICEENDPOINT is the endpoint to reach your member's CA


# for example ca.m-K46ICRRXJRCGRNNS4ES4XUUS5A.n-MWY63ZJZU5HGNCMBQER7IN6OIU.managedblockchain.us-east-1.amazonaws.com:30002


export CASERVICEENDPOINT=MyMemberCaEndpoint





# ORDERER is the endpoint to reach your network's orderer


# for example orderer.n-MWY63ZJZU5HGNCMBQER7IN6OIU.managedblockchain.MyRegion.amazonaws.com:30001


export ORDERER=MyNetworkOrdererEndpoint





export GOHOME=/home/ec2-user/go/bin


export PATH=$GOHOME:$PATH
 
In your ~/.bashrc file can you put comments in front of the following lines so that they look like this.
Code:
#if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
#then
#PATH="$HOME/.local/bin:$HOME/bin:$PATH"
#fi
#export PATH
And then in your ~/.bash_profile make the following lines look like this.
Code:
export GOHOME=/home/ec2-user/go/bin
export PATH=$GOHOME:$HOME/.local/bin:$HOME/bin:$PATH
Run the following and share the output again.
Code:
source ~/.bash_profile
which go
echo $PATH
 
In your ~/.bashrc file can you put comments in front of the following lines so that they look like this.
Code:
#if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
#then
#PATH="$HOME/.local/bin:$HOME/bin:$PATH"
#fi
#export PATH
And then in your ~/.bash_profile make the following lines look like this.
Code:
export GOHOME=/home/ec2-user/go/bin
export PATH=$GOHOME:$HOME/.local/bin:$HOME/bin:$PATH
Run the following and share the output again.
Code:
source ~/.bash_profile
which go
echo $PATH
Sorry for the late reply.

Have updated the Code in the /.bash_profile and here you are the following Output:


[ec2-user@ip-172-31-22-105 ~]$ nano ~/.bash_profile


[ec2-user@ip-172-31-22-105 ~]$ source ~/.bash_profile


[ec2-user@ip-172-31-22-105 ~]$ which go


~/go/bin/go


[ec2-user@ip-172-31-22-105 ~]$ echo $PATH


/home/ec2-user/go/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/home/ec2-user/go/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin


[ec2-user@ip-172-31-22-105 ~]$ go version


-bash: /home/ec2-user/go/bin/go: cannot execute binary file: Exec format error
 
What happens when you run the following?
Code:
/home/ec2-user/go/bin/go version
Can you share the output of the following?
Code:
ls -l ~/go/bin
ls -l /home/ec2-user/go/bin
It's -l not -1, so small letter L.
 
What happens when you run the following?
Code:
/home/ec2-user/go/bin/go version
Can you share the output of the following?
Code:
ls -l ~/go/bin
ls -l /home/ec2-user/go/bin
It's -l not -1, so small letter L.
Here you are the Output:


[ec2-user@ip-172-31-22-105 ~]$ /home/ec2-user/go/bin/go version


-bash: /home/ec2-user/go/bin/go: cannot execute binary file: Exec format error


[ec2-user@ip-172-31-22-105 ~]$ ls -l ~/go/bin


total 18628


-rwxr-xr-x. 1 ec2-user ec2-user 15645180 Apr 26 15:35 go


-rwxr-xr-x. 1 ec2-user ec2-user 3427131 Apr 26 15:35 gofmt


[ec2-user@ip-172-31-22-105 ~]$ ls -l ~/home/ec2-user/go/bin


ls: cannot access '/home/ec2-user/home/ec2-user/go/bin': No such file or directory


Note: I think we delete One of them? Because 2 different files are having the same, what do you think?
 
[ec2-user@ip-172-31-22-105 ~]$ ls -l ~/home/ec2-user/go/bin


ls: cannot access '/home/ec2-user/home/ec2-user/go/bin': No such file or directory
This is wrong it should be one of these, can you share the output of both?
Code:
ls -l /home/ec2-user/go/bin 
ls -l ~go/bin
Using "~go/bin" will expand to /home/ec2-user/go/bin
Can you also share the output of the following again?
Code:
which go
[ec2-user@ip-172-31-22-105 ~]$ echo $PATH
/home/ec2-user/go/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/home/ec2-user/go/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin
Looking at this it looks like the directory you want is fist in your PATH so which should give back to correct binary.
However the following shows that something is not correct with your binary.
Here you are the Output:


[ec2-user@ip-172-31-22-105 ~]$ /home/ec2-user/go/bin/go version


-bash: /home/ec2-user/go/bin/go: cannot execute binary file: Exec format error
How did you install go in that location?
 
This is wrong it should be one of these, can you share the output of both?
Code:
ls -l /home/ec2-user/go/bin
ls -l ~go/bin
Using "~go/bin" will expand to /home/ec2-user/go/bin
Can you also share the output of the following again?
Code:
which go

Looking at this it looks like the directory you want is fist in your PATH so which should give back to correct binary.
However the following shows that something is not correct with your binary.

How did you install go in that location?
Here you are as per the details:


[ec2-user@ip-172-31-22-105 ~]$ ls -l /home/ec2-user/go/bin


total 18628


-rwxr-xr-x. 1 ec2-user ec2-user 15645180 Apr 26 15:35 go


-rwxr-xr-x. 1 ec2-user ec2-user 3427131 Apr 26 15:35 gofmt
[ec2-user@ip-172-31-22-105 ~]$ ls -l ~ go/bin

/home/ec2-user:

total 97840

-rw-r--r--. 1 ec2-user ec2-user 951 May 2 11:17 bash_profile

drwxr-xr-x. 24 ec2-user ec2-user 16384 May 4 08:07 fabric-samples

drwxr-xr-x. 10 ec2-user ec2-user 16384 Apr 26 15:36 go

-rw-r--r--. 1 ec2-user ec2-user 100148454 May 2 17:21 go1.20.4.linux-amd64.tar.gz



go/bin:

total 18628

-rwxr-xr-x. 1 ec2-user ec2-user 15645180 Apr 26 15:35 go

-rwxr-xr-x. 1 ec2-user ec2-user 3427131 Apr 26 15:35 gofmt

[ec2-user@ip-172-31-22-105 ~]$ cd go

[ec2-user@ip-172-31-22-105 go]$ ls -l

total 76

-rw-r--r--. 1 ec2-user ec2-user 1339 Apr 26 15:31 CONTRIBUTING.md

-rw-r--r--. 1 ec2-user ec2-user 1479 Apr 26 15:31 LICENSE

-rw-r--r--. 1 ec2-user ec2-user 1303 Apr 26 15:31 PATENTS

-rw-r--r--. 1 ec2-user ec2-user 1455 Apr 26 15:31 README.md

-rw-r--r--. 1 ec2-user ec2-user 419 Apr 26 15:31 SECURITY.md

-rw-r--r--. 1 ec2-user ec2-user 8 Apr 26 15:31 VERSION

drwxr-xr-x. 2 ec2-user ec2-user 16384 Apr 26 15:34 api

drwxr-xr-x. 2 ec2-user ec2-user 29 Apr 26 15:35 bin

-rw-r--r--. 1 ec2-user ec2-user 52 Apr 26 15:31 codereview.cfg

drwxr-xr-x. 2 ec2-user ec2-user 104 Apr 26 15:34 doc

drwxr-xr-x. 3 ec2-user ec2-user 18 Apr 26 15:34 lib

drwxr-xr-x. 11 ec2-user ec2-user 152 Apr 26 15:34 misc

drwxr-xr-x. 4 ec2-user ec2-user 33 Apr 26 15:35 pkg

drwxr-xr-x. 50 ec2-user ec2-user 16384 Apr 26 15:34 src

drwxr-xr-x. 26 ec2-user ec2-user 16384 Apr 26 15:34 test


Note: Kindly excuse me for 30-40min and I will be right back, thanks.
 
I download the same go version and did the same as you.
Code:
[tux@ansibletest ~]$ tail -n2 .bash_profile
export GOHOME=/home/tux/go/bin
export PATH=$GOHOME:$HOME/.local/bin:$HOME/bin:$PATH
[tux@ansibletest ~]$ source .bash_profile
[tux@ansibletest ~]$ ls -l
total 97808
drwxr-xr-x. 10 tux tux      4096 Apr 26 17:36 go
-rw-r--r--.  1 tux tux 100148454 May 10 13:29 go1.20.4.linux-amd64.tar.gz
[tux@ansibletest ~]$ ls -l go
total 52
drwxr-xr-x.  2 tux tux  4096 Apr 26 17:34 api
drwxr-xr-x.  2 tux tux    29 Apr 26 17:35 bin
-rw-r--r--.  1 tux tux    52 Apr 26 17:31 codereview.cfg
-rw-r--r--.  1 tux tux  1339 Apr 26 17:31 CONTRIBUTING.md
drwxr-xr-x.  2 tux tux   104 Apr 26 17:34 doc
drwxr-xr-x.  3 tux tux    18 Apr 26 17:34 lib
-rw-r--r--.  1 tux tux  1479 Apr 26 17:31 LICENSE
drwxr-xr-x. 11 tux tux   152 Apr 26 17:34 misc
-rw-r--r--.  1 tux tux  1303 Apr 26 17:31 PATENTS
drwxr-xr-x.  4 tux tux    33 Apr 26 17:35 pkg
-rw-r--r--.  1 tux tux  1455 Apr 26 17:31 README.md
-rw-r--r--.  1 tux tux   419 Apr 26 17:31 SECURITY.md
drwxr-xr-x. 49 tux tux  4096 Apr 26 17:34 src
drwxr-xr-x. 26 tux tux 12288 Apr 26 17:34 test
-rw-r--r--.  1 tux tux     8 Apr 26 17:31 VERSION
[tux@ansibletest ~]$ ls -l go/bin/
total 18628
-rwxr-xr-x. 1 tux tux 15645180 Apr 26 17:35 go
-rwxr-xr-x. 1 tux tux  3427131 Apr 26 17:35 gofmt
[tux@ansibletest ~]$ go version
go version go1.20.4 linux/amd64
Can you share the output of the following?
Code:
uname -a
Could you put code tags next time you share your output that makes it more readable?
 
I download the same go version and did the same as you.
Code:
[tux@ansibletest ~]$ tail -n2 .bash_profile
export GOHOME=/home/tux/go/bin
export PATH=$GOHOME:$HOME/.local/bin:$HOME/bin:$PATH
[tux@ansibletest ~]$ source .bash_profile
[tux@ansibletest ~]$ ls -l
total 97808
drwxr-xr-x. 10 tux tux      4096 Apr 26 17:36 go
-rw-r--r--.  1 tux tux 100148454 May 10 13:29 go1.20.4.linux-amd64.tar.gz
[tux@ansibletest ~]$ ls -l go
total 52
drwxr-xr-x.  2 tux tux  4096 Apr 26 17:34 api
drwxr-xr-x.  2 tux tux    29 Apr 26 17:35 bin
-rw-r--r--.  1 tux tux    52 Apr 26 17:31 codereview.cfg
-rw-r--r--.  1 tux tux  1339 Apr 26 17:31 CONTRIBUTING.md
drwxr-xr-x.  2 tux tux   104 Apr 26 17:34 doc
drwxr-xr-x.  3 tux tux    18 Apr 26 17:34 lib
-rw-r--r--.  1 tux tux  1479 Apr 26 17:31 LICENSE
drwxr-xr-x. 11 tux tux   152 Apr 26 17:34 misc
-rw-r--r--.  1 tux tux  1303 Apr 26 17:31 PATENTS
drwxr-xr-x.  4 tux tux    33 Apr 26 17:35 pkg
-rw-r--r--.  1 tux tux  1455 Apr 26 17:31 README.md
-rw-r--r--.  1 tux tux   419 Apr 26 17:31 SECURITY.md
drwxr-xr-x. 49 tux tux  4096 Apr 26 17:34 src
drwxr-xr-x. 26 tux tux 12288 Apr 26 17:34 test
-rw-r--r--.  1 tux tux     8 Apr 26 17:31 VERSION
[tux@ansibletest ~]$ ls -l go/bin/
total 18628
-rwxr-xr-x. 1 tux tux 15645180 Apr 26 17:35 go
-rwxr-xr-x. 1 tux tux  3427131 Apr 26 17:35 gofmt
[tux@ansibletest ~]$ go version
go version go1.20.4 linux/amd64
Can you share the output of the following?
Code:
uname -a
Could you put code tags next time you share your output that makes it more readable?
Hi,

I'm back and sorry for the delay.

Here you are:

uname -a

Linux ip-172-31-22-105.ec2.internal 6.1.23-36.46.amzn2023.aarch64 #1 SMP Mon Apr 10 22:42:58 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux
 
uname -a

Linux ip-172-31-22-105.ec2.internal 6.1.23-36.46.amzn2023.aarch64 #1 SMP Mon Apr 10 22:42:58 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux
You are trying to run an amd64 compiled binary on an aarch64 system. You will need to download this version(go1.20.4.linux-arm64.tar.gz) in order for you to be able to run it on that system.
 


Top