Reputation: 215
I need to read some hardware data with privileges permissions, so I need to use the asdf plugin as root. How can I do that?
I tried to start the root user sudo su
but I cannot access asdf
Upvotes: 4
Views: 7113
Reputation: 741
Check where your bins are (e.g. which iex
), in my case
/home/<user>/.asdf/shims/
Become root bringing the user env with you
sudo -Es
Export the shims (as pointed by the error)
export PATH=/home/riccardo/.asdf/shims/:$PATH
You are good to go :thumbup:
Upvotes: 1
Reputation: 51
Something like
sudo -E $(which asdf) list
or in fish
sudo -E (which asdf) list
Replace asdf
with needed asdf plugin, and put the command argument afterwards, like list
above
Upvotes: 0
Reputation: 2155
The existing answer on this post pointed me in the right direction: sudo -E
is required in order to carry over environment variables (including the important PATH
) into the sudo shell.
However, I was still getting the unknown command: THECOMMAND. Perhaps you have to reshim?
. What worked for me is getting the path to both the command you want to run and the binary you want to run it through.
In my case, I was trying to use the hostile
host management tool. It failed because it couldn't find node
. By specifying both the full node
path and the direct path to the hostile
script I was able to get around the reshim errors.
sudo -E `asdf which node` `asdf which hostile` load the_file.txt
Upvotes: 1
Reputation: 488
tl;dr: sudo -E su
The problem is that sudo
doesn't preserve (most) environment variables by default. For asdf
, the environment variables ASDF_CONFIG_FILE
, ASDF_DATA_DIR
, and ASDF_DIR
are all important, along with the usual suspects, like PATH
.
Fortunately, we can instruct sudo
to keep all the environment variables around. From man sudo
:
-E, --preserve-env
Indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the user does not have permission to preserve the environment.
Resources:
Upvotes: 11