Upgrading Java and Setting as Default on Raspberry Pi - java

I'm new to Raspberry-Pi & Linux and I wanted to code up a Minecraft server using PaperMC, but when I ran the server I got a warning saying that Java-11 would no longer be supported in future builds, so I thought it would be easy enough to upgrade to Java-16. I have not found documentation regarding this topic specifically which has led to using parts of differing tutorials, and I think I made a few mistakes. To start, I purged the old Java-11 version like so:
sudo -i
apt-get purge openjdk*
apt-get purge java11*
apt-get autoremove
Then I moved to the jvm directory and installed Java-16 from AdpotOpenJDK:
cd /usr/lib/jvm
wget https://github.com/AdoptOpenJDK/openjdk16-binaries/releases/download/jdk-16.0.1%2B9/OpenJDK16U-jre_aarch64_linux_hotspot_16.0.1_9.tar.gz
tar xzf OpenJDK16U-jre_aarch64_linux_hotspot_16.0.1_9.tar.gz
export PATH=$PWD/jdk-16.0.1+9-jre/bin:$PATH
java -version
openjdk version "16.0.1" 2021-04-20
OpenJDK Runtime Environment AdoptOpenJDK-16.0.1+9 (build 16.0.1+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK-16.0.1+9 (build 16.0.1+9, mixed mode, sharing)
This export PATH command seems to be temporary, when I logout of sudo or exit the command window, and then check java -version again I get that the java command is not found. If I try setting JAVA_HOME & PATH:
export JAVA_HOME="/usr/lib/jvm/jdk-16.0.1+9-jre"
export PATH=$PATH:$JAVA_HOME/bin
The result is also temporary. Why can't I set this Java-16 as the default? Do I need to make a script that runs these commands on startup?

Here is a way to install it permanently using apt. Link to the information
https://paper.readthedocs.io/en/latest/java-update/index.html#debian-ubuntu
$ sudo apt update
$ sudo apt install apt-transport-https software-properties-common gnupg wget
$ wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -
$ sudo add-apt-repository https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
$ sudo apt update
$ sudo apt install adoptopenjdk-16-hotspot

Related

How to create docker image with nodejs 12, java, gcc, g++,python3, monocs

I am trying to dockerize my NodeJs & Express API . In my API iam using https://www.npmjs.com/package/compile-run package to compile and run C,
Cpp,Java,JavaScript(Node.js env), Python languages.
This package requires all 5 compilers(gcc,g++,nodejs,python3,javac) installed on the server. If any compiler misses, it throws error.
In my local(undockerized) the API is working completely fine on both windows & ubuntu(As I have installed compilers on them).
I am trying to replicate the same on my docker image. But I am stuck.
Look at my
Dockerfile:
FROM node:12
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
CMD ["npm","start"]
I think node-12 image comes along with gcc, g++,python3 and nodejs(obviously).
But the issue is with java. I am not able to compile java code.
so I tried it this way
FROM node:12
RUN apt-get -y install default-jre
# RUN java -version
RUN apt -y install default-jre
RUN apt install openjdk-11-jre-headless
RUN java -version
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
CMD ["npm","start"]
But I am not able to install open-jdk or open-jre with apt/apt-get.
What is the right way to configure docker?
This is my nodeJS API repository https://github.com/yogendramaarisetty/online-compiler-api
First you must update the package list with apt-get update, then you can install openjdk-8. openjdk-11 isn't available with that distribution of node. I used docker run -it node:12 /bin/bash to see what there was,
FROM node:12
RUN apt-get update && apt-get install -y openjdk-8-jdk
For example,
$ cat Dockerfile
FROM node:12
RUN apt-get update && apt-get install -y openjdk-8-jdk
$ docker build --tag mynode:1.0 .
$ docker run -it mynode:1.0 /bin/bash
root#d70858199dd1:/# java -version
openjdk version "1.8.0_265"
OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0+deb9u1-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)
root#d70858199dd1:/# javac -version
javac 1.8.0_265
root#d70858199dd1:/#
If you really do need Java 11, there are multiple ways and places to get openjdk-11. One is bell-sw. For example,
$ cat Dockerfile
FROM node:12
RUN apt-get update && apt-get install -y libasound2 libxtst6
RUN wget https://download.bell-sw.com/java/11.0.7+10/bellsoft-jdk11.0.7+10-linux-amd64.deb && \
apt install ./bellsoft-jdk11.0.7+10-linux-amd64.deb
$ docker build --tag mynode:1.1 .
$ docker run -it mynode:1.1 /bin/bash
root#37771ce98727:/# java -version
openjdk version "11.0.7" 2020-04-14 LTS
OpenJDK Runtime Environment (build 11.0.7+10-LTS)
OpenJDK 64-Bit Server VM (build 11.0.7+10-LTS, mixed mode)
root#37771ce98727:/# javac -version
javac 11.0.7

Install latest java version in ubuntu 16.04 [duplicate]

How do I install Java Development Kit (JDK) 10 on Ubuntu?
The installation instructions on Oracle's help center only explain how to download and extract the archive on Linux platform, without any system setup.
Update: JDK 11 Now Available
sudo apt-get install openjdk-11-jdk
For JDK 10
Option 1: Easy Installation (PPA)
sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt-get install oracle-java10-installer
Then set as default with:
sudo apt-get install oracle-java10-set-default
And finally verify Installation with:
$ java -version
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
Source: Linux Uprising
Option 2: Manual Installation
Download OpenJDK 10 binaries for Linux.
Untar the downloaded archive:
tar xzvf openjdk-10_linux-x64_bin.tar.gz
Move the extracted archive to where your system keeps your installed JDKs:
sudo mv jdk-10 /usr/lib/jvm/java-10-openjdk-amd64/
Add the new Java alternative:
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-10-openjdk-amd64/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-10-openjdk-amd64/bin/javac 1
Update your system's java alternatives and choose JDK 10:
$ sudo update-alternatives --config java
here are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-9-openjdk-amd64/bin/java 1091 auto mode
* 1 /usr/lib/jvm/java-10-openjdk-amd64/bin/java 1 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
3 /usr/lib/jvm/java-9-openjdk-amd64/bin/java 1091 manual mode
Press <enter> to keep the current choice[*], or type selection number:
and
$ sudo update-alternatives --config javac
There are 3 choices for the alternative javac (providing /usr/bin/javac).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-9-openjdk-amd64/bin/javac 1091 auto mode
1 /usr/lib/jvm/java-10-openjdk-amd64/bin/javac 1 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 manual mode
3 /usr/lib/jvm/java-9-openjdk-amd64/bin/javac 1091 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/lib/jvm/java-10-openjdk-amd64/bin/javac to provide /usr/bin/javac (javac) in manual mode
Verify your installation with:
$ java --version
openjdk 10 2018-03-20
OpenJDK Runtime Environment 18.3 (build 10+46)
OpenJDK 64-Bit Server VM 18.3 (build 10+46, mixed mode)
and
$ javac --version
javac 10
Done
If you prefer Oracle's JDK, download it and follow the installation steps as shown above.
I've found SdkMan! a very useful tool because it provides a convenient way for managing your JDKs from the shell.
For example, once it is installed, you can:
Install a specific JDK version: sdk install java 10.0.2-open
Downloading: java 10.0.2-open
In progress...
################# 12,3%
Use a specific JDK version: sdk use java 10.0.2-open
Using java version 10.0.2-open in this shell.
List available JDK: sdk list java
===================================================================
Available Java Versions
===================================================================
9.0.4-open
+ 8u161-oracle
8.0.191-oracle
> + 8.0.171-oracle
7.0.191-zulu
12.ea.15-open
11.0.1-open
10.0.2-open
1.0.0-rc8-graal
===================================================================
+ - local version
* - installed
> - currently in use
=======================================================================
And much more
See https://sdkman.io/usage
There is a ppa on java 10 that installs oracle's java: https://launchpad.net/~linuxuprising/+archive/ubuntu/java
I am not sure if this will be maintained though.
It seems to be a copy of the webupd8 way on how to handle oracle java installation (ref: documentation).
How to use this ppa:
sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt-get install oracle-java10-installer
Verify installation:
$ /usr/lib/jvm/java-10-oracle/bin/java -version
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
Setting up environment variables (make java10 default)
sudo apt-get install oracle-java10-set-default
Note: You need update-alternatives only if you have multiple java versions.
Note: You can purge everything about Java before fresh installing new Java.
sudo apt purge java*
For Java 10 fresh installation
Download JDK 10 from here (you can download JRE and server JRE): http://www.oracle.com/technetwork/java/javase/downloads/index.html
Extract and put somewhere in /opt/java directory. You putting JDK in /opt/java directory makes it will be usable for all users as it is being in the public /opt directory.
(Note: I downloaded JDK, JRE, and server JRE, and extracted JDK and renamed extracted the folder to jdk10, extracted JRE and renamed extracted the folder to jre10, and extracted server JRE and renamed extracted the folder to jre10server as shown in below snapshot).
Update your /etc/environment file as below
Now, you need to reload the /etc/environment script file into the system using source command as below.
source /etc/environment
If you want to know more about update-alternatives then here is the link: https://askubuntu.com/questions/159575/how-do-i-make-java-default-to-a-manually-installed-jre-jdk
You need to do update-alternatives --install before the final step.
sudo update-alternatives --install "/usr/bin/java" java "/usr/lib/jvm/java-10-openjdk-amd64/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" javac "/usr/lib/jvm/java-10-openjdk-amd64/bin/javac" 1
I've found a repo
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt update
sudo apt install openjdk-10-jdk
Repo home page
Install Jdk 10 On Linux Ubuntu
Download the required tarball from from Oracle official
website, i.e.
https://www.oracle.com
Unzip this tarball using "tar -zxvf tarball_name”
Create a folder named "java" in "/usr/lib", you need root permission
sudo mkdir /usr/lib/java
Move the extracted folder to “/usr/lib/java/” by using the following command:
sudo mv java-10-dir-name/ /usr/lib/java/
Now go to the location, i.e. cd /usr/lib/java/java-10-dir-name/
Next, run these below scripts in terminal:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/java/java-10-dir-name/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/java/java-10-dir-name/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/java/java-10-dir-name/bin/javaws" 1
NOTE: In the commands given above, you have to name the extracted directory of "java" instead of "java-10-dir-name".
Update the JAVA_HOME in your ~/.bashrc
export JAVA_HOME=/usr/lib/java/java-10-dir-name
set PATH="$PATH:$JAVA_HOME/bin"
export PATH
Verify the installation
verify whether Java 10 is installed correctly in your machine, execute the following command in your terminal:
$ java --version
openjdk 10 2018-03-20
OpenJDK Runtime Environment 18.3 (build 10+46)
OpenJDK 64-Bit Server VM 18.3 (build 10+46, mixed mode)
And
$ javac --version
javac 10

jmap command not found

I'm trying to use the jmap command on my CentOS server but it keeps telling me that the command was not found even though I have the JDK installed.
Here is the output of command java -version:
java version "1.7.0_25"
OpenJDK Runtime Environment (rhel-2.3.10.4.el6_4-x86_64)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
How can I fix this issue?
You should be able to find jmap in the java-1.8.0-openjdk-devel-debug, or java-1.7.0-openjdk-devel-debug, or java-1.6.0-openjdk-devel-debug packages on Redhat/Centos. To install it, run the following as root:
yum install java-1.8.0-openjdk-devel-debug
For completeness, here's the command to check which packages include jmap:
yum whatprovides '*/jmap'
Here's a sample output:
1:java-1.6.0-openjdk-devel-1.6.0.37-1.13.9.4.el7_1.x86_64 : OpenJDK Development Environment
Repo : updates
Matched from:
Filename : /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.37.x86_64/bin/jmap
1:java-1.7.0-openjdk-devel-1.7.0.91-2.6.2.3.el7.x86_64 : OpenJDK Development Environment
Repo : base
Matched from:
Filename : /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64/bin/jmap
1:java-1.8.0-openjdk-devel-1.8.0.65-3.b17.el7.x86_64 : OpenJDK Development Environment
Repo : base
Matched from:
Filename : /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64/bin/jmap
1:java-1.8.0-openjdk-devel-debug-1.8.0.65-3.b17.el7.x86_64 : OpenJDK Development Environment with full debug on
Repo : base
Matched from:
Filename : /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64-debug/bin/jmap
1:java-1.8.0-openjdk-devel-debug-1.8.0.65-3.b17.el7.x86_64 : OpenJDK Development Environment with full debug on
Repo : #base
Matched from:
Filename : /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64-debug/bin/jmap
The following worked for me:
sudo apt-get install openjdk-8-jdk openjdk-8-dbg
My situation was a little strange (running inside the openjdk:8-jre Docker image), but this combination worked
cat /etc/debian_version # 8.6
apt install -t jessie-backports openjdk-8-jre-headless ca-certificates-java
apt-get install -f -y openjdk-8-jdk-headless
apt-get install -f -y openjdk-8-dbg
the java path must be in the "PATH" systemproperty.
$JAVA_HOME/bin
it doesn't come default with JRE -- you should be able to install it with below command
yum install java-1.8.0-openjdk-devel-debug
for Debian "buster" - 10.3 -
cat /etc/debian_version # 10.3
echo "deb http://ftp.us.debian.org/debian sid main" > /etc/apt/sources.list.d/buster.list
apt-get update && apt-get install -f -y openjdk-8-jdk-headless openjdk-8-dbg
OpenJDK on centos doesn't include the jmap utility. test on another platform or use the jhat java_pid1234.hprof command to examine the dump after the fact on another platform.
jhat can be slow to run on large dumps and even run out of memory! I use jhat -port 7000 -J-mx2048m java_pid1234.hprof so you'll need plenty of ram on your computer.
I found that on my system (elasticsearch container) it is excluded:
$ grep exclude /etc/yum.conf
exclude=java-1.8.0-openjdk*
If I comment it out then I can see and install this package with yum install ...

how to set path in terminal on ubuntu for java?

I have recently installed ubuntu and want to start compiling programs in the terminal. What is the command to set the path for java in ubuntu terminal? I tried "cd path" but it did not work. Could anyone please tell me the right command?
first of all if you have not installed java you need to execute the command
$ sudo apt-get install openjdk-7-jdk
if it does not work then first execute
$ sudo apt-get update
and the execute the above command
and the do
$ sudo vi /etc/profile
and at the last line of the file add
JAVA_HOME={path to java home}
PATH=$JAVA_HOME/bin:$PATH
and do $ . /etc/profile
and now you are good to go
to see the effect type java -version
Actually, you can avoid set the path by following phase:
First you can add ppa:
$ sudo add-apt-repository ppa:webupd8team/java
Then update:
$ sudo apt-get update
Then install it:
$ sudo apt-get install oracle-java8-installer
Finally, check it using the following command:
$ java -version
Result:
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) Server VM (build 25.5-b02, mixed mode)
Try export command.
Check in which location jdk is installed ( in ubuntu, its mostly in /usr/java/(javaVersion))
update the path variable using export:
export PATH=$PATH:/usr/java/(javaVersion)/bin

how to remove default-jre java installation from Ubuntu?

I had no java (i.e. java -version said java no found or similar)
I installed it like this:
sudo apt-get install default-jre
This results in installing java 1.6 - I need java 1.7
So the next probelem is how to uninstall it.
I tried this:
sudo apt-get --purge -remove default-jre
Which seemed to work, but when I do:
java -version
I still java respond with 1.6 - i.e. id didnt uninstall java.
Ok, so I guess -remove does not remove the thing it installed. Is there a way to o this?
To completely remove jdk from your system, follow these below steps:
Type sudo apt-get autoremove default-jdk openjdk- (Don't hit Enter right now).
Now press tab button for 2 or 3 times, you will get list of packages
starting with openjdk-.
Look for name like openjdk-11-jdk. You need to get java version,
here is 11.
Now complete your command to sudo apt-get autoremove default-jdk
openjdk-11-jdk. (Change 11 to your java version)
And Hit Enter button.
Now you have done removing java from your system.
sudo apt-get remove default-jre
removes the package "default-jre". all tho you should ask in askUbuntu
Bary12's answer worked for me:
sudo apt-get autoremove default-jre
To set the Java version interactively:
Log in as root or use sudo.
View the Java alternatives.
$ update-alternatives --config java
This command lists the Java installations and prompts to select from the choices.
Sample response
There are 4 programs which provide 'java'.
Selection Command
1 /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
2 * /usr/lib/jvm/zulu-6/bin/java
3 /usr/lib/jvm/zulu-7/bin/java
4 /usr/lib/jvm/zulu-8/bin/java
Select a Java version, at the prompt, type a number.
Press enter to keep the default[*], or type selection number:
Sample response
Using '/usr/lib/jvm/zulu-7/bin/java' to provide 'java'.
Verify the switch, check the Java version.
$ java -version
Sample response
openjdk version "1.7.0_65"
OpenJDK Runtime Environment (Zulu 7.6.0.1-linux64) (build 1.7.0_65-b17)
OpenJDK 64-Bit Server VM (Zulu 7.6.0.1-linux64) (build 24.65-b04, mixed mode)
To set the Java version by path:
Log in as root or use sudo.
Specify the path to use when running Java.
$ update-alternatives --set java /usr/lib/jvm/zulu8/bin/java
You can remove Java 12 using this command--
sudo apt-get remove oracle-java12-installer
you can change the version by changing the 12 to the version present on your computer
then recheck by finding version -
java -version
I Installed Default JDK like this
sudo apt install -y default-jdk
Removed like this
sudo apt remove openjdk-11-jre-headless openjdk-11-jre openjdk-11-jdk-headless openjdk-11-jdk

Categories

Resources