11

I decided to update my JDK7 to recent version from here.

Corresponding x64 tag.gz archive for my architecture has been downloaded and extracted to /usr/lib/jvm as usual. All previous versions of Java were installed before the same way. But before setting new alternatives for java, javac and javaws I removed all existing alternatives using the following commands:

sudo update-alternatives --remove-all java
sudo update-alternatives --remove-all javac
sudo update-alternatives --remove-all javaws

Now when trying to install new alternatives I get the following:

sudo update-alternatives --install /usr/lib/jvm/jdk1.7.0_13/bin/java java /usr/bin/java 1
update-alternatives: error: alternative path /usr/bin/java doesn't exist.

Of course, /usr/bin/java doesn't exist but /usr/bin does? What's wrong with it and how can I fix it?

ezze
  • 810

3 Answers3

9

It's my epic fault! :)

I mixed up the arguments of update-alternatives. The right command line must be:

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk/bin/java 1
ezze
  • 810
2

Since you are updating from a previous Java version, which you have removed manually, you would have to execute the following command twice. You get an error message the first time and it works when you execute it the second time.

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk/bin/java" 1

Source: Easy Linux Project

kutschkem
  • 193
Aditya
  • 13,616
-1

Oracle have made java installation very easy, and hope for the future as well. One can download latest debain from Oracle. Run the following commands to install:

1. sudo apt install ./jdk-17_linux-x64_bin.deb
2. sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-17/bin/java 2

Note:- Run command 1 where .deb file is stored, jdk version might be different. Similarly for command 2, use tab, while typing the command, for second argument i.e. /usr/lib/jvm/jdk- then type downloaded version, in my case it is 17.

If an older version of java (<17) is already installed then visit Linux Up Rising and run the following commands:

1. sudo add-apt-repository ppa:linuxuprising/java
2. sudo apt update
  1. sudo -i

  2. echo "deb http://ppa.launchpad.net/linuxuprising/java/ubuntu focal main" | tee /etc/apt/sources.list.d/linuxuprising-java.list

  3. apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 73C3DB2A

  4. apt-get update

  5. exit

  6. sudo apt install oracle-java17-installer --install-recommends

  7. java -version

Output:
java version "17.0.1" 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)