how fix mistake made with update-alternatives?

9,258

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:
9,258

Related videos on Youtube

Phil Freihofner
Author by

Phil Freihofner

Composer, Oboist, Database Programmer My main programming passion is with Java, a language I greatly admire, with an emphasis on games and audio. I've also dabbling with texture generation via Simplex noise but mostly leave the high-powered graphics coding to others. I have two github repositories: AudioCue: an enhanced version of java's Clip, allowing for concurrent playback and real time control of volume, pan, and speed-of-playback. The tool implements Listeners and can be used with a virtual audio mixer to funnel all cue playback into a single output line. Sivi: a tool for visualizing 2D gradient noise, currently implementing Simplex and OpenSimplex. It is possible to see directly the effect of mixing channels of noise and to have the noise modulate a few simple canned gradients. The settings can be used to write your own procedural noise generation, or, the tool can export jpg, gif, png, and can also make and export z-axis animated gifs. I also have some sample programs linked at Adonax.com, a portfolio site. As far a professional coding, my main experience is with VBA and Microsoft Access, which I have been doing for umpteen years. I'm currently working through courses on Hibernate and HTML/CSS, Android and JavaFX. My first game programming was with FORTH, in the early 1980's, for a company called Unison World, Inc. at the time (later Kyocera Unison, but I had left and gone back for my music degree at UC Berkeley by the time that happened). My first introduction to computer science came from my father, Anton Freihofner II, who worked for IBM and was the main coder for the 1960's iteration of the Mormon Genealogy database.

Updated on September 18, 2022

Comments

  • Phil Freihofner
    Phil Freihofner almost 2 years

    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.

    • George Udosen
      George Udosen over 5 years
      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!
    • Phil Freihofner
      Phil Freihofner over 5 years
      Solved! Thank you. Would you like to enter this as an answer? I'd be happy to select it.