3

I can't understand from the update-alternatives documentation how the priorities system works.

Suppose that I want /usr/bin/node to point to nodejs for nodejs applications and to an amateur radio program, called node, in other cases. I have to say:

update-alternatives --install /usr/bin/node nodejs /usr/bin/nodejs 100 --slave /usr/share/man/...

Suppose I have 2 programs that expect /usr/bin/node to be different things, first - nodejs, second - amateur radio. How would they determine which one to use?

What's the role of priority in this process?

ADDITION: Note, that npm, nodejs package manager, expects nodejs command to be called node, thus I have to install nodejs as node.

1

At any time, /usr/bin/node can only be one of the programs. The alternatives mechanism is a way to choose which one it is.

Priorities control which one is the default when both are installed. They don't offer a way to somehow have both and select between the two based on what other program called this one.

When programs call each other by name, there can only be a single program by a given name that comes first on the search path. You should disambiguate the node command in your programs. Following Debian, use nodejs for Node.js and ax25-node for the HAM program. If there's one that it would be really annoying to change, install either the node package (which makes /usr/bin/node an alias for ax25-node) or the nodejs-legacy package (which makes /usr/bin/node an alias for nodejs).

If you really have a lot of programs that call node and that can't be changed easily, run them with different PATH variables, one containing a directory containing a symbolic link to ax25-node and one containing a directory containing a symbolic link to nodejs:

mkdir -p /usr/local/etc/nodejs/bin /usr/local/etc/ax25/bin
ln -s ../../../../bin/nodejs /usr/local/etc/nodejs/bin/node
ln -s ../../../../bin/ax25-node /usr/local/etc/ax25/bin/node

PATH=/usr/local/etc/ax25/bin:$PATH program-using-ax25
PATH=/usr/local/etc/node/bin:$PATH program-using-nodejs
  • Thanks for the answer, Gilles! So, what's the purpose of alternatives system, if it doesn't allow to switch symlink for different programs? – Boris Burkov Sep 14 '15 at 7:11
  • 1
    it does allow to switch the symlink, but only on a system-wide basis, not a per-user basis. – Jasen Sep 14 '15 at 9:19
8

I think you're misunderstanding the role of the alternatives system here. It is used to provide a simple way to use alternative programs of a similar type. The usual example, and the one used in the man page is an editor:

For example, if the text editors ed(1) and nvi(1) are both installed on the system, the alternatives system will cause the generic name /usr/bin/editor to refer to /usr/bin/nvi by default.

In your case, node refers to two completely different applications.

If both are installable from the main Debian repository then chances are that one of the package maintainers will have named their executable so that it doesn't clash with the other. For example, the binary for the radio application could have been renamed to /usr/bin/node_radio so that it doesn't clash with the Node.js /usr/bin/node.

On the other hand, if you're compiling the amateur radio node yourself, you must ensure that you either alter the compilation so that it doesn't create the same name binary or ensure that it is installed into a different path, such as /usr/local/bin/node. If you opt for the latter, then which node is executed when you type it at the command prompt depends on the search order in your $PATH variable. If the wrong one is executed, you'll have to enter the full path to run it: /usr/local/bin/node.

In any case update-alternatives doesn't help you here.

All the above is only an example as a quick check with apt-get download node followed by dpkg --contents node_0.3.2-7.4_all.deb shows that the amateur radio node is installed as /usr/sbin/ax25-node with a link from /usr/sbin/node to the executable. Node.js installs /usr/bin/nodejs therefore the two will never clash.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.