how fix mistake made with update-alternatives?












0















In the process of installing OpenJDK 11 (via a download), and attempting to set the environment variable and defaults to invoke this version instead of the previously installed Java 10, I have messed up the ability of Ubuntu to find Java. The current error message follows:



phil@UBI-VirtualBox:~/JavaApps$ java -version
bash: /usr/bin/java: No such file or directory



The following is the chronology of actions that led to this problem.



I installed OpenJDK 11 in /usr/lib/jvm/jdk-11.0.1 file folder.
The /usr/lib/jvm folder also has other Java versions (e.g., /java-ll-openjdk-amd64, which actually runs java 10).



I then created a JAVA_HOME variable and set it with the preferred java version. The environment variable is now listed in both /etc/environment



JAVA_HOME="/usr/lib/jvm/jdk-11.0.1"


and as the last line in ~/.bashrc



export JAVA_HOME=/usr/lib/jvm/jdk-11.0.1


At that point, when attempting to check via "java -version" I found that JAVA_HOME works fine, but that my default still pointed to the previously installed Java 10.



phil@UBI-VirtualBox:~$ java -version
openjdk version "10.0.2" 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4, mixed mode)
phil@UBI-VirtualBox:~$ $JAVA_HOME/bin/java -version
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)


It was at this point I figured out that update-alternatives was playing a role.



Unfortunately, I seem to have screwed things up by putting in an erroneous command:



phil@UBI-VirtualBox:~$ sudo update-alternatives --install /usr/lib/jvm java /usr/lib/jvm/jdk-11.0.1/bin/java 3
update-alternatives: renaming java link from /usr/bin/java to /usr/lib/jvm
update-alternatives: warning: forcing reinstallation of alternative /usr/lib/jvm/java-11-openjdk-amd64/bin/java because link group java is broken
update-alternatives: warning: not replacing /usr/lib/jvm with a link
phil@UBI-VirtualBox:~$ sudo update-alternatives --install /usr/lib/java java /usr/lib/jvm/jdk-11.0.1/bin/java 3
update-alternatives: warning: forcing reinstallation of alternative /usr/lib/jvm/java-11-openjdk-amd64/bin/java because link group java is broken
phil@UBI-VirtualBox:~$ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/lib/java).

Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
3 /usr/lib/jvm/jdk-11.0.1/bin/java 3 manual mode

Press <enter> to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/lib/jvm/jdk-11.0.1/bin/java to provide /usr/lib/java (java) in manual mode


Now, when running "java -version" I get the following error message:



phil@UBI-VirtualBox:~/JavaApps$ java -version
bash: /usr/bin/java: No such file or directory


Inspecting /usr/bin for a "java" file, I find that none exist. There is a "javac" link that points to the /ext/alternatives folder (as well as other links such as "jar").



The /ext/alternatives folder has both a "javac" and "java" links in it. Both "javac" and "java" point to the desired java version. (I had also added the alternatives to javac.)



In addition, the folder that holds the jvms (/usr/lib/jvm) also holds yet another "java" link file. This one points to "/etc/alternatives/java". And there is a "default-java" file-folder link that points to the undesired Java version.



I tried copying the link to "/etc/alternatives/java" from /usr/lib/jvm to /usr/bin, but the resulting icon did not have an arrow and did not work, so I deleted it. Command used to copy:



sudo cp /usr/lib/jvm/java /usr/bin/java 


I thought I better stop thrashing around before making things even worse and ask how to fix this.



BTW, JAVA_HOME still works fine.










share|improve this question


















  • 1





    Run this command again phil@UBI-VirtualBox:~$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.1/bin/java 3, then run sudo update-alternatives --config java and fix it there!

    – George Udosen
    Jan 4 at 1:07











  • Solved! Thank you. Would you like to enter this as an answer? I'd be happy to select it.

    – Phil Freihofner
    Jan 4 at 2:25
















0















In the process of installing OpenJDK 11 (via a download), and attempting to set the environment variable and defaults to invoke this version instead of the previously installed Java 10, I have messed up the ability of Ubuntu to find Java. The current error message follows:



phil@UBI-VirtualBox:~/JavaApps$ java -version
bash: /usr/bin/java: No such file or directory



The following is the chronology of actions that led to this problem.



I installed OpenJDK 11 in /usr/lib/jvm/jdk-11.0.1 file folder.
The /usr/lib/jvm folder also has other Java versions (e.g., /java-ll-openjdk-amd64, which actually runs java 10).



I then created a JAVA_HOME variable and set it with the preferred java version. The environment variable is now listed in both /etc/environment



JAVA_HOME="/usr/lib/jvm/jdk-11.0.1"


and as the last line in ~/.bashrc



export JAVA_HOME=/usr/lib/jvm/jdk-11.0.1


At that point, when attempting to check via "java -version" I found that JAVA_HOME works fine, but that my default still pointed to the previously installed Java 10.



phil@UBI-VirtualBox:~$ java -version
openjdk version "10.0.2" 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4, mixed mode)
phil@UBI-VirtualBox:~$ $JAVA_HOME/bin/java -version
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)


It was at this point I figured out that update-alternatives was playing a role.



Unfortunately, I seem to have screwed things up by putting in an erroneous command:



phil@UBI-VirtualBox:~$ sudo update-alternatives --install /usr/lib/jvm java /usr/lib/jvm/jdk-11.0.1/bin/java 3
update-alternatives: renaming java link from /usr/bin/java to /usr/lib/jvm
update-alternatives: warning: forcing reinstallation of alternative /usr/lib/jvm/java-11-openjdk-amd64/bin/java because link group java is broken
update-alternatives: warning: not replacing /usr/lib/jvm with a link
phil@UBI-VirtualBox:~$ sudo update-alternatives --install /usr/lib/java java /usr/lib/jvm/jdk-11.0.1/bin/java 3
update-alternatives: warning: forcing reinstallation of alternative /usr/lib/jvm/java-11-openjdk-amd64/bin/java because link group java is broken
phil@UBI-VirtualBox:~$ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/lib/java).

Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
3 /usr/lib/jvm/jdk-11.0.1/bin/java 3 manual mode

Press <enter> to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/lib/jvm/jdk-11.0.1/bin/java to provide /usr/lib/java (java) in manual mode


Now, when running "java -version" I get the following error message:



phil@UBI-VirtualBox:~/JavaApps$ java -version
bash: /usr/bin/java: No such file or directory


Inspecting /usr/bin for a "java" file, I find that none exist. There is a "javac" link that points to the /ext/alternatives folder (as well as other links such as "jar").



The /ext/alternatives folder has both a "javac" and "java" links in it. Both "javac" and "java" point to the desired java version. (I had also added the alternatives to javac.)



In addition, the folder that holds the jvms (/usr/lib/jvm) also holds yet another "java" link file. This one points to "/etc/alternatives/java". And there is a "default-java" file-folder link that points to the undesired Java version.



I tried copying the link to "/etc/alternatives/java" from /usr/lib/jvm to /usr/bin, but the resulting icon did not have an arrow and did not work, so I deleted it. Command used to copy:



sudo cp /usr/lib/jvm/java /usr/bin/java 


I thought I better stop thrashing around before making things even worse and ask how to fix this.



BTW, JAVA_HOME still works fine.










share|improve this question


















  • 1





    Run this command again phil@UBI-VirtualBox:~$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.1/bin/java 3, then run sudo update-alternatives --config java and fix it there!

    – George Udosen
    Jan 4 at 1:07











  • Solved! Thank you. Would you like to enter this as an answer? I'd be happy to select it.

    – Phil Freihofner
    Jan 4 at 2:25














0












0








0








In the process of installing OpenJDK 11 (via a download), and attempting to set the environment variable and defaults to invoke this version instead of the previously installed Java 10, I have messed up the ability of Ubuntu to find Java. The current error message follows:



phil@UBI-VirtualBox:~/JavaApps$ java -version
bash: /usr/bin/java: No such file or directory



The following is the chronology of actions that led to this problem.



I installed OpenJDK 11 in /usr/lib/jvm/jdk-11.0.1 file folder.
The /usr/lib/jvm folder also has other Java versions (e.g., /java-ll-openjdk-amd64, which actually runs java 10).



I then created a JAVA_HOME variable and set it with the preferred java version. The environment variable is now listed in both /etc/environment



JAVA_HOME="/usr/lib/jvm/jdk-11.0.1"


and as the last line in ~/.bashrc



export JAVA_HOME=/usr/lib/jvm/jdk-11.0.1


At that point, when attempting to check via "java -version" I found that JAVA_HOME works fine, but that my default still pointed to the previously installed Java 10.



phil@UBI-VirtualBox:~$ java -version
openjdk version "10.0.2" 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4, mixed mode)
phil@UBI-VirtualBox:~$ $JAVA_HOME/bin/java -version
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)


It was at this point I figured out that update-alternatives was playing a role.



Unfortunately, I seem to have screwed things up by putting in an erroneous command:



phil@UBI-VirtualBox:~$ sudo update-alternatives --install /usr/lib/jvm java /usr/lib/jvm/jdk-11.0.1/bin/java 3
update-alternatives: renaming java link from /usr/bin/java to /usr/lib/jvm
update-alternatives: warning: forcing reinstallation of alternative /usr/lib/jvm/java-11-openjdk-amd64/bin/java because link group java is broken
update-alternatives: warning: not replacing /usr/lib/jvm with a link
phil@UBI-VirtualBox:~$ sudo update-alternatives --install /usr/lib/java java /usr/lib/jvm/jdk-11.0.1/bin/java 3
update-alternatives: warning: forcing reinstallation of alternative /usr/lib/jvm/java-11-openjdk-amd64/bin/java because link group java is broken
phil@UBI-VirtualBox:~$ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/lib/java).

Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
3 /usr/lib/jvm/jdk-11.0.1/bin/java 3 manual mode

Press <enter> to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/lib/jvm/jdk-11.0.1/bin/java to provide /usr/lib/java (java) in manual mode


Now, when running "java -version" I get the following error message:



phil@UBI-VirtualBox:~/JavaApps$ java -version
bash: /usr/bin/java: No such file or directory


Inspecting /usr/bin for a "java" file, I find that none exist. There is a "javac" link that points to the /ext/alternatives folder (as well as other links such as "jar").



The /ext/alternatives folder has both a "javac" and "java" links in it. Both "javac" and "java" point to the desired java version. (I had also added the alternatives to javac.)



In addition, the folder that holds the jvms (/usr/lib/jvm) also holds yet another "java" link file. This one points to "/etc/alternatives/java". And there is a "default-java" file-folder link that points to the undesired Java version.



I tried copying the link to "/etc/alternatives/java" from /usr/lib/jvm to /usr/bin, but the resulting icon did not have an arrow and did not work, so I deleted it. Command used to copy:



sudo cp /usr/lib/jvm/java /usr/bin/java 


I thought I better stop thrashing around before making things even worse and ask how to fix this.



BTW, JAVA_HOME still works fine.










share|improve this question














In the process of installing OpenJDK 11 (via a download), and attempting to set the environment variable and defaults to invoke this version instead of the previously installed Java 10, I have messed up the ability of Ubuntu to find Java. The current error message follows:



phil@UBI-VirtualBox:~/JavaApps$ java -version
bash: /usr/bin/java: No such file or directory



The following is the chronology of actions that led to this problem.



I installed OpenJDK 11 in /usr/lib/jvm/jdk-11.0.1 file folder.
The /usr/lib/jvm folder also has other Java versions (e.g., /java-ll-openjdk-amd64, which actually runs java 10).



I then created a JAVA_HOME variable and set it with the preferred java version. The environment variable is now listed in both /etc/environment



JAVA_HOME="/usr/lib/jvm/jdk-11.0.1"


and as the last line in ~/.bashrc



export JAVA_HOME=/usr/lib/jvm/jdk-11.0.1


At that point, when attempting to check via "java -version" I found that JAVA_HOME works fine, but that my default still pointed to the previously installed Java 10.



phil@UBI-VirtualBox:~$ java -version
openjdk version "10.0.2" 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4, mixed mode)
phil@UBI-VirtualBox:~$ $JAVA_HOME/bin/java -version
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)


It was at this point I figured out that update-alternatives was playing a role.



Unfortunately, I seem to have screwed things up by putting in an erroneous command:



phil@UBI-VirtualBox:~$ sudo update-alternatives --install /usr/lib/jvm java /usr/lib/jvm/jdk-11.0.1/bin/java 3
update-alternatives: renaming java link from /usr/bin/java to /usr/lib/jvm
update-alternatives: warning: forcing reinstallation of alternative /usr/lib/jvm/java-11-openjdk-amd64/bin/java because link group java is broken
update-alternatives: warning: not replacing /usr/lib/jvm with a link
phil@UBI-VirtualBox:~$ sudo update-alternatives --install /usr/lib/java java /usr/lib/jvm/jdk-11.0.1/bin/java 3
update-alternatives: warning: forcing reinstallation of alternative /usr/lib/jvm/java-11-openjdk-amd64/bin/java because link group java is broken
phil@UBI-VirtualBox:~$ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/lib/java).

Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
3 /usr/lib/jvm/jdk-11.0.1/bin/java 3 manual mode

Press <enter> to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/lib/jvm/jdk-11.0.1/bin/java to provide /usr/lib/java (java) in manual mode


Now, when running "java -version" I get the following error message:



phil@UBI-VirtualBox:~/JavaApps$ java -version
bash: /usr/bin/java: No such file or directory


Inspecting /usr/bin for a "java" file, I find that none exist. There is a "javac" link that points to the /ext/alternatives folder (as well as other links such as "jar").



The /ext/alternatives folder has both a "javac" and "java" links in it. Both "javac" and "java" point to the desired java version. (I had also added the alternatives to javac.)



In addition, the folder that holds the jvms (/usr/lib/jvm) also holds yet another "java" link file. This one points to "/etc/alternatives/java". And there is a "default-java" file-folder link that points to the undesired Java version.



I tried copying the link to "/etc/alternatives/java" from /usr/lib/jvm to /usr/bin, but the resulting icon did not have an arrow and did not work, so I deleted it. Command used to copy:



sudo cp /usr/lib/jvm/java /usr/bin/java 


I thought I better stop thrashing around before making things even worse and ask how to fix this.



BTW, JAVA_HOME still works fine.







java update-alternatives






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 22:10









Phil FreihofnerPhil Freihofner

1034




1034








  • 1





    Run this command again phil@UBI-VirtualBox:~$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.1/bin/java 3, then run sudo update-alternatives --config java and fix it there!

    – George Udosen
    Jan 4 at 1:07











  • Solved! Thank you. Would you like to enter this as an answer? I'd be happy to select it.

    – Phil Freihofner
    Jan 4 at 2:25














  • 1





    Run this command again phil@UBI-VirtualBox:~$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.1/bin/java 3, then run sudo update-alternatives --config java and fix it there!

    – George Udosen
    Jan 4 at 1:07











  • Solved! Thank you. Would you like to enter this as an answer? I'd be happy to select it.

    – Phil Freihofner
    Jan 4 at 2:25








1




1





Run this command again phil@UBI-VirtualBox:~$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.1/bin/java 3, then run sudo update-alternatives --config java and fix it there!

– George Udosen
Jan 4 at 1:07





Run this command again phil@UBI-VirtualBox:~$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.1/bin/java 3, then run sudo update-alternatives --config java and fix it there!

– George Udosen
Jan 4 at 1:07













Solved! Thank you. Would you like to enter this as an answer? I'd be happy to select it.

– Phil Freihofner
Jan 4 at 2:25





Solved! Thank you. Would you like to enter this as an answer? I'd be happy to select it.

– Phil Freihofner
Jan 4 at 2:25










1 Answer
1






active

oldest

votes


















1














To fix it simply run the following commands



sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.1/bin/java 3
sudo update-alternatives --config java


The first correct the errors you made where you had /usr/lib/jvm it should have been /usr/bin/java. The second command gives you the opportunity to pick the default version you want.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1106736%2fhow-fix-mistake-made-with-update-alternatives%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    To fix it simply run the following commands



    sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.1/bin/java 3
    sudo update-alternatives --config java


    The first correct the errors you made where you had /usr/lib/jvm it should have been /usr/bin/java. The second command gives you the opportunity to pick the default version you want.






    share|improve this answer




























      1














      To fix it simply run the following commands



      sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.1/bin/java 3
      sudo update-alternatives --config java


      The first correct the errors you made where you had /usr/lib/jvm it should have been /usr/bin/java. The second command gives you the opportunity to pick the default version you want.






      share|improve this answer


























        1












        1








        1







        To fix it simply run the following commands



        sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.1/bin/java 3
        sudo update-alternatives --config java


        The first correct the errors you made where you had /usr/lib/jvm it should have been /usr/bin/java. The second command gives you the opportunity to pick the default version you want.






        share|improve this answer













        To fix it simply run the following commands



        sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.1/bin/java 3
        sudo update-alternatives --config java


        The first correct the errors you made where you had /usr/lib/jvm it should have been /usr/bin/java. The second command gives you the opportunity to pick the default version you want.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 4 at 6:11









        George UdosenGeorge Udosen

        20.8k94569




        20.8k94569






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1106736%2fhow-fix-mistake-made-with-update-alternatives%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to change which sound is reproduced for terminal bell?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

            Can I use Tabulator js library in my java Spring + Thymeleaf project?