14

Is there any way to use update-alternative "user wide" ? I mean that it would be great to set preferences per user.

Does Debian provide some tools for that?

Falcon Momot
  • 25,244
  • 15
  • 63
  • 92
Maxime
  • 251
  • 1
  • 2
  • 6

4 Answers4

18

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).

Sam Brightman
  • 825
  • 1
  • 8
  • 12
2

Users who don't want to use the system default for an application that uses the alternatives (and an alternate is indeed installed) can always simply use either the correct name or full path for the non-default alternative or set up an alias overruling the symbolic link.

HBruijn
  • 77,029
  • 24
  • 135
  • 201
2

Each user can create their own bin directory for example in ~/bin and put that first in their PATH. Inside that directory they can have symlinks to their preferred alternative.

I don't know whether they can use the update-alternative command to update their own directory of symlinks, or if they have to do that manually.

kasperd
  • 30,455
  • 17
  • 76
  • 124
  • I ended up creating an "update-alternative"-like script that each user can use for their own needs. – Maxime Sep 30 '14 at 07:30
0

I know this is an old question, but I wanted to chime in with a blatant promotion for the tool I just released that helps you configure per-user (or even per-shell !) alternatives:

You can initialize a shell-specific setup:

$ eval "$( my-alternatives init)"

Or you can initialize a long-lived user-level setup:

# run this once
$ eval "$( my-alternatives init ~/my-alts )"

# place this in your startup scripts
$ eval "$( my-alternatives shellenv ~/my-alts )"

Once configured, setting up a user-local alternative is as easy as:

# equivalent to 'update-alternatives --config <name>'
$ my-alternatives config <name>

NOTE: At the time of this posting, my-alternatives was just released. As such, only init and config logic has been built. Other features will come later.