10

I'm using a shared server. On that server different versions of Java are installed:

  Selection    Path                                      Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      auto mode
* 1            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-6-sun/jre/bin/java       63        manual mode

I would like to choose the Second options, but if I tried to do that it complains that I do not have the permissions (I'm not root).

Is there a way to do that in "user-space"?

Can the Root user make this preference works only for me?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Aslan986
  • 501
  • 1
  • 4
  • 10
  • The accepted answer is probably preferrable here but if you genuinely need to use your own alternatives see [my answer at ServerFault](http://serverfault.com/a/811377/3654). – Sam Brightman Oct 26 '16 at 10:14

2 Answers2

12

On Debian and derivates, you should probably use update-java-alternatives. Anyway, all those tools are system related, not user related. If you want to use a different java, simply put those lines in your ~/.profile:

JAVA_HOME=/usr/lib/jvm/java-6-sun
JRE_HOME=/usr/lib/jvm/java-6-sun/jre
PATH=$JAVA_HOME/bin:"$PATH"
export JAVA_HOME JRE_HOME
eppesuig
  • 3,208
  • 1
  • 14
  • 13
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.