Score:0

how can I use golang as a new user?

in flag

I'm working on a shell script that installs some binaries as systemd service. To keep things clean, the service is running under a new user. I want to keep all binaries in the home of that new user. The problem is that I need to build the binary using go.

It seems that my newly created user does not find go and I would like some pointers on how to tell it where to find it.

Here's the shell script that I'm using for the task:

#!/bin/bash
sudo adduser --disabled-password --home /home/erigon --shell /bin/bash --gecos "" erigon
sudo -u erigon git clone --branch stable --single-branch https://github.com/ledgerwatch/erigon.git /home/erigon/erigon
cd /home/erigon/erigon
sudo make erigon

which fails with /bin/sh: 1: go: not found

I do have go installed for my normal user:

$ go version
go version go1.18.2 linux/amd64

But indeed the new user does not see it:

$ sudo -u erigon go version
sudo: go: command not found
Score:1
in flag

Likely make is being run in an environment that does not have go in its path. This may be related to how you are running the script rather than the user account itself. Problems like this are common for scripts run at the system level, e.g., from cron or systemd, where the path is either not set or set to some bare minimum default.

If this is purely a path problem, the easiest solution is to explicitly set the path to something suitable in the script.

Go is not "installed" for your "normal" user. It's just that when you use sudo to change users, your path isn't getting set correctly. Here's some things to check:

  • In the user where it works, try echo $PATH and see what the correct path is.
  • When using sudo to change users, use sudo -Hsu erigon instead; this sets the home directory correctly and then gives you a shell. again use echo $PATH and check to see if the path is correct. If not, fix it, copying the previous correct path. Then things should work.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.