Home › Forums › FABRIC General Questions and Discussion › go does not work with node.execute API
- This topic has 4 replies, 4 voices, and was last updated 1 year, 8 months ago by Sajith Sasidharan.
-
AuthorPosts
-
March 30, 2023 at 12:51 pm #4006
Hello,
I tried to install go and yanfd before I ssh to the node. I did that by the following code:
try: for node in slice.get_nodes(): stdout, stderr = node.execute('curl -O -L "https://golang.org/dl/go1.19.5.linux-amd64.tar.gz"') stdout, stderr = node.execute('tar -xf "go1.19.5.linux-amd64.tar.gz"') stdout, stderr = node.execute('sudo mv -v go /usr/local') stdout, stderr = node.execute('echo "export GOPATH=$HOME/go" >> ~/.bashrc') stdout, stderr = node.execute('echo "export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin" >> ~/.bashrc') stdout, stderr = node.execute('echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.bashrc') stdout, stderr = node.execute('go install github.com/named-data/YaNFD/cmd/yanfd@latest') except Exception as e: print(f"Exception: {e}")
I got the error that
bash: go: command not found
. However, I could use go as I ssh to the node. I was wondering what might cause this error.Thanks,
Best Regards,
Xusheng- This topic was modified 1 year, 8 months ago by Xusheng Ai.
March 30, 2023 at 1:33 pm #4008This is the updated code but it still does not work with the same error:
try: for node in slice.get_nodes(): stdout, stderr = node.execute('curl -O -L "https://golang.org/dl/go1.19.5.linux-amd64.tar.gz"') stdout, stderr = node.execute('tar -xf "go1.19.5.linux-amd64.tar.gz"') stdout, stderr = node.execute('sudo mv -v go /usr/local') stdout, stderr = node.execute('echo "export GOPATH=$HOME/go" >> ~/.bashrc') stdout, stderr = node.execute('echo "export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin" >> ~/.bashrc') stdout, stderr = node.execute('echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.bashrc') stdout, stderr = node.execute('source ~/.bashrc') stdout, stderr = node.execute('go install github.com/named-data/YaNFD/cmd/yanfd@latest') except Exception as e: print(f"Exception: {e}")
- This reply was modified 1 year, 8 months ago by Xusheng Ai.
April 1, 2023 at 4:45 pm #4019Each of those execute calls creates a separate ssh session that runs the the command. This means that each of the calls runs in its own shell and the result of any pervious ‘export’ or ‘source’ calls will not be represented in the environment of a new call.
In this case you are putting everything in the .bashrc file, so I would think that the new call would source the .bashrc file when the shell is created but maybe there is some other piece of the environment missing.
Try putting that all in one call, something like this:
node.execute('curl -O -L "https://golang.org/dl/go1.19.5.linux-amd64.tar.gz" ;' 'tar -xf "go1.19.5.linux-amd64.tar.gz" ;' 'sudo mv -v go /usr/local ;' 'echo "export GOPATH=$HOME/go" >> ~/.bashrc ;' 'echo "export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin" >> ~/.bashrc ;' 'echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.bashrc ;' 'source ~/.bashrc ;' 'go install github.com/named-data/YaNFD/cmd/yanfd@latest')
April 2, 2023 at 7:16 pm #4026Hi, I tried the provided remedy which lead to the same error “go: command not found”.
However, I did find a possibly temporary solution. Instead of saying “go install ….“, you list the full path rather than the alias itself. For example: “/usr/local/go/bin/go install …“. This solution might be limited as it will not work in situations where programs need a reference to GOPATH or PATH (w Go included).
- This reply was modified 1 year, 8 months ago by Justin Presley.
April 18, 2023 at 12:23 pm #4110Perhaps the shell isn’t bash? On many systems (Debian and perhaps Ubuntu too),
/bin/sh
is a symbolic link to dash, not bash. On other systems, bash too will attempt to conform to POSIX standard if it is invoked assh
via a symbolic link.In either of those cases
PATH
might get picked up from~/.profile
, not~/.bashrc
. -
AuthorPosts
- You must be logged in to reply to this topic.