0

In Debian Stable the latest openjdk version available is 17.

$ which -a java /usr/bin/java /bin/java $ java --version openjdk 17.0.8 2023-07-18 OpenJDK Runtime Environment (build 17.0.8+7-Debian-1deb12u1) OpenJDK 64-Bit Server VM (build 17.0.8+7-Debian-1deb12u1, mixed mode, sharing) 

I wanted to test out 21 which will be released soon so I downloaded the binaries directly.

$ curl https://download.java.net/java/GA/jdk21/fd2272bbf8e04c3dbaee13770090416c/35/GPL/openjdk-21_linux-x64_bin.tar.gz $ tar -xzf openjdk-21_linux-x64_bin.tar.gz $ cd jdk-21 $ ./bin/java --version openjdk 21 2023-09-19 OpenJDK Runtime Environment (build 21+35-2513) OpenJDK 64-Bit Server VM (build 21+35-2513, mixed mode, sharing) $ which -a java /usr/bin/java /bin/java $ java --version openjdk 17.0.8 2023-07-18 OpenJDK Runtime Environment (build 17.0.8+7-Debian-1deb12u1) OpenJDK 64-Bit Server VM (build 17.0.8+7-Debian-1deb12u1, mixed mode, sharing) 

I would like all my scripts to use the new java binaries without having to manually edit all java entries in them. That is, when invoking java I would like the new binaries to run. Can I replace stock java by simply copy pasting to /usr/bin/ and /bin/? That is, will this work?

$ mv ./bin/* /usr/bin/ $ mv ./bin/* /bin/ 

Do I also need to copy other folders in jdk-21 such as conf and lib? Can replacing stock java cause any side effects?

1
  • Don't. It's always a bad idea to make changes to a installed package by other means than using the corresponding package manager.
    – Tom Yan
    CommentedAug 29, 2023 at 6:28

1 Answer 1

1

Simply modify PATH so that realpath ./bin comes first.

For example, in ~/.bashrc, you can use export PATH="/home/yyhh344/Downloads/java-21/bin:$PATH".

You may also need to set JAVA_HOME and other Java environment variables depending on your usage.

    You must log in to answer this question.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.