简体   繁体   中英

How does one install opam without sudo priveledges on linux/ubuntu?

I am working on a HPC that I don't have sudo privileges. I tried 3 ways to install opam but they didn't work

Option 1 the .deb approach

I did:

# - opam (snap, no sudo)
# ref: https://askubuntu.com/questions/339/how-can-i-install-a-package-without-root-access
apt-get download opam
#apt-get download opam_1.2.2-4_amd64
#ls | less
mkdir -p ~/.local
dpkg -x opam_1.2.2-4_amd64.deb ~/.local/bin
export PATH="$HOME/.local/bin:$PATH"
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc.user

tr ':' '\n' <<< "$PATH"

opam --version

but it leads to missing compiler options and it also doesn't allow me to update opam with opam update --all . Error msg when I try to update :

$ opam update --all

<><> Updating package repositories ><><><><><><><><><><><><><><><><><><><><><><>
Processing  1/1: [default: http]
[default] synchronised from https://opam.ocaml.org
[ERROR] Could not update repository "default": "~/anaconda/bin/patch -p1 -i /dfs/scratch0/brando9/.opam/log/patch-99014-0624b6" exited with code 2

Option 2 using conda

Usually this is the way I've done it in my docker containers (due to someone else's suggestions):

conda install -c conda-forge opam

but it leads to the following error :

...

ClobberError: The package 'conda-forge/noarch::pip-22.3.1-pyhd8ed1ab_0' cannot be installed due to a
path collision for 'lib/python3.9/site-packages/pip/_vendor/requests/__pycache__/packages.cpython-39.pyc'.
This path already exists in the target prefix, and it won't be removed
by an uninstall action in this transaction. The path is one that conda
doesn't recognize. It may have been created by another package manager.

...

I also wonder if the fact that I did this error is the reason option 1 is not working see error of option 1.

Option 3 using the usual hack: download git repo then install binaries to a location you specify

mkdir ~/.opam
cd ~/.opam
git clone https://github.com/rbenv/opam.git .

export PATH="$HOME/.opam/bin:$PATH"
echo 'export PATH="$HOME/.opam/bin:$PATH"' >> ~/.bashrc

eval $(opam env)
opam update --all
opam init --disable-sandboxing
eval $(opam env)

Option 4, following the install instructions from opam

I realize there is a 4th option that I will try again right now and report. I assume it didn't work or I'd be using it (though no user interaction would be nice):

$ bash -c "sh <(curl -fsSL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh)"
## Downloading opam 2.1.3 for linux on x86_64...
## Downloaded.
## Where should it be installed ? [/usr/bin] ~/.local/
## '~/.local/' resolves to '/dfs/scratch0/brando9/.local/', do you confirm [Y/n] Y
Write access to /usr/bin required, using 'sudo'.
Command: mv /usr/bin/opam /usr/bin/opam.1.2.2
[sudo] password for brando9:
Sorry, user brando9 is not allowed to execute '/bin/mv /usr/bin/opam /usr/bin/opam.1.2.2' as root on hyperturing2.stanford.edu.

I tried the above but now that the administrators installed opam it doesn't let me. Hopefully I do have permissions to update opam etc...or I might have to ask them to uninstall it or at least update it.


Seems that this works:

$ bash -c "sh <(curl -fsSL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh)"
## Downloading opam 2.1.3 for linux on x86_64...
## Downloaded.
## Where should it be installed ? [/usr/bin] ~/.local/
## '~/.local/' resolves to '/dfs/scratch0/brando9/.local/', do you confirm [Y/n] Y

Will test if afterwords I can do what I truly need:

opam init --disable-sandboxing
opam update --all
eval $(opam env)
# compiler + '_' + coq_serapi + '.' + coq_serapi_pin
# ref: https://stackoverflow.com/questions/74697011/how-does-one-install-a-specific-ocaml-compiler-when-it-doesnt-appear-on-the-opa
opam switch create ocaml-variants.4.07.1+flambda_coq-serapi.8.11.0+0.11.1 ocaml-variants.4.07.1+flambda
opam switch ocaml-variants.4.07.1+flambda_coq-serapi.8.11.0+0.11.1
eval $(opam env)

opam repo add coq-released https://coq.inria.fr/opam/released
# opam pin add -y coq 8.11.0
opam repo --all-switches add --set-default coq-released https://coq.inria.fr/opam/released
opam update --all
opam pin add -y coq 8.11.0

#opam install -y --switch ocaml-variants.4.07.1+flambda_coq-serapi_coq-serapi_8.11.0+0.11.1 coq-serapi 8.11.0+0.11.1
opam install -y coq-serapi

eval $(opam env)

# - install utop
opam install utop

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM