How to use update-alternatives per user

Yes, you can absolutely use update-alternatives for yourself. For example, I have different LLVM versions installed under ~/.local/llvm-VERSION. I can install binary links into ~/.local/bin (which is in my $PATH) like this:

alias update-my-alternatives='update-alternatives --altdir ~/.local/etc/alternatives --admindir ~/.local/var/lib/alternatives'
mkdir -p ~/.local/var/lib/alternatives ~/.local/etc/alternatives
version=3.9.0
slaves=""
for b in llvm-${version}/bin/*; do \
    slaves+=" --slave $HOME/.local/bin/$(basename $b) $(basename $b) $(readlink -f $b)" \
done
update-my-alternatives --install $HOME/.local/bin/llvm-config llvm $(readlink -f $(dirname $b)/llvm-config) ${version//./0} ${slaves}

I can repeat the last command for new versions and use update-my-alternatives --config llvm to choose between versions.

If you want to use the pre-existing system alternatives, you could possibly copy over all the files in /var/lib/alternatives to ~/.local/var/lib/alternatives and change all of the system paths in the first section to be user paths (e.g. change /usr to /home/username/.local).

Tags:

Debian

Users