52

I typed:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/ jdk1.8.0/bin/java" 1

It's says alternatives --install needs link name path priority

6
  • 1
    What are you typing exactly? please be careful with any punctuation (e.g. dashes) and spaces Jul 5, 2014 at 16:42
  • @steeldriver could you explain link name path priority . If there were no link like "/user/bin/java/" then will erroneous result?
    – Swapnil
    Jul 5, 2014 at 16:53
  • 1
    It should create the link (and the name if there is no current java group in /etc/alternatives). AFAIK the only thing that must pre-exist is the path component i.e. /usr/lib/jvm/jdk1.8.0/bin/java - but note that (as posted in your question) you have a space in yours - hence my 1st comment. Jul 5, 2014 at 16:58
  • @steeldriver yeah /usr/lib/jvm/bin/java/ is available . I've try sudo update-alternatives -- install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0.05/bin/java" 1
    – Swapnil
    Jul 5, 2014 at 17:22
  • 1
    Are you leaving a space between the -- and the word install? if so, don't - it needs to be --install. Also the quotes should not be necessary, just sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0.05/bin/java 1 Jul 5, 2014 at 17:35

4 Answers 4

69

Are you leaving a space between the -- and the word install? if so, don't - it needs to be --install

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0.05/bin/java 1

The quotes should not be necessary since none of the elements have embedded spaces - although they shouldn't do any harm.

2
  • 1
    Also, keep in mind that relative paths aren't accepted here, you must use the absolute path. Jul 10, 2018 at 8:06
  • what is the range of priority numbers?, thanks in advance. Sep 21, 2019 at 18:47
17

The command sintax is

sudo update-alternatives --install <link> <name> <path> <priority>

if there are no space in the parameters, you don't need quotes.

In your case:

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0/bin/java 1

Pay attention: did you really have a space in the path before jdk?

2
  • What is the difference between <link> and <path>?
    – hafiz031
    Jul 4, 2020 at 19:15
  • 1
    @hafiz031 <path> is the path to executable (for example my java installation), instead <link> is the fake executable, a link that points to the real executable. If you add another jdk, you use the same link (/usr/bin/java) but another jdk. The link is in the $PATH system variable Jul 6, 2020 at 8:50
4

Just trying to contribute with this post. I use this command, once that I know my setup correctly.

echo 1 | sudo update-alternatives --config java
3

This is beacause this command maintains symbolic links. I recommend to execute man update-alternatives to get more information about the command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .