How does one install opam without sudo in ubuntu without interaction from the user?

I think it works if I run their bash script they give and then manually give it the location I want that doesn’t require sudo, but when I try to echo the location that doesn’t need sudo it doesn’t work. Why?

Interactive (works):

apt-get update && apt-get install -y lsb-release && apt-get clean all && apt-get install -y curl
mkdir -p ~/.local/
bash -c "sh <(curl -fsSL"
# I manually typed the local were I do have permissions:

fails non interactive:

# idk if this one works
echo "~/.local/" | bash -c "sh <(curl -fsSL"


1 Like

I’m a little confused. Typically these days, I download an opam binary, stick it in a directory, put that directory on my path, and go opam init and off we go to the races. Typically I also set an environment (OPAMROOT IIRC, been a while) so that my opam root is not my homedir/.opam, but that’s a nuance.

Why does one need to invoke apt at all? Other than for installing stuff like bbwrap, I mean ?

1 Like

The official docs recommend using your distro’s package manager to install opam:

Ah. OK. I don’t remember where I saw “you can just download the opam binary and put it on your search-path”. But it works great!

I do the same as you: (1) download the opam binary for my system from Releases · ocaml/opam · GitHub , (2) put that somewhere in my PATH where I have permission to do so, and (3) then use it to compile and install a switch for my chosen compiler (having the default ~/.opam as the local opam directory for this works fine for me). I am somewhat bemused by the difficulties reported here and on stackoverflow using specialized installers.