Why Is Alternatives Command Used When Installing Java on a Linux MAChine

Why is alternatives command used when installing Java on a Linux machine

It's not specific to Linux, only some of the distributions. It's better for maintaining multiple versions of the software or libraries and easily switch between them. Your applications are only pointing to the symbolic link, which you can easily switch any time and don't have to go through all the configurations of your applications.
I don't know what the 20000 means, but here's the manpage: http://linux.about.com/library/cmd/blcmdl8_alternatives.htm (but you should have that in your system too)

When and Why run alternatives --install java jar javac javaws on installing jdk in linux

When you install JDK on Linux, what gets installed depends on the type of package, version and distribution. You can refer to the following links for information about the installation location on linux:

JDK Installation for Linux Platforms - Version 8

JDK Installation for Linux Platforms - Version 7

Once you install JDK, the bin folder containing tools might not get added to the environment variable PATH. Commands typed on the terminal needs to be from the locations specified in the PATH variable. In cases when JDK\bin does not get added, the user would need to configure it manually as mentioned in Installing the JDK Software

alternatives command is being used to create a symbolic link. Here, it is being directed to use the command to add the tools like javac, javaw to /usr/bin which exists in the PATH variable by default.

If( you could execute java -version outside of JDK/bin && not by specifying the complete path && if the version and bundle prints to be as that of package you installed ){ you need not run the alternatives command.}

Have bash script answer interactive prompts

This is not "auto-completion", this is automation. One common tool for these things is called Expect.

You might also get away with just piping input from yes.

OpenJDK and update-alternatives command

While this can be a problem for many software, this is a specific problem for Java on Ubuntu. Fortunately there is a specific solution, a program, call:

update-java-alternatives

I have just use it the following way:

sudo update-java-alternatives -s java-1.14.0-openjdk-amd64

It have change the alternatives of most of the Java related tools.

More comment on this subject can be found on askubuntu for a similar question. This question is also related, and an answer link to the same program.

alternatives --config java bash script

Generally, you can feed any program that expects something on the standard input like this:

echo -e "line 1\nline 2\nline 3" | program

/usr/bin/alternatives command throws usage error

That should be --install with two hyphens, not –install with an em-dash or -install with one hyphen.

update-alternatives: warning: /etc/alternatives/java is dangling

Assuming you installed the OpenJDK6 with:

sudo apt-get install openjdk-6-jdk

In Ubuntu 64 bit, make sure the paths are valid for your installation (change if using 32bit version):

/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java

/usr/lib/jvm/java-6-openjdk-amd64/bin/javac

Setup update-alternatives:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java-6-openjdk-amd64/bin/javac" 1

sudo update-alternatives --set java /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/java-6-openjdk-amd64/bin/javac

Alternatively, make sure the correct version is checked for both Java and compiler:

sudo update-alternatives --config java
sudo update-alternatives --config javac

List the installed Java alternatives with:

sudo update-alternatives --list java
sudo update-alternatives --list javac


Related Topics



Leave a reply



Submit