Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symlink installed java to /usr/java/latest

Tags:

linux

bash

A program requires a java directory location of /usr/java/latest. In many cases this directory does not exist. In order to get the program to run correctly I need to do the following steps:

mkdir -p /usr/java
mkdir -p /usr/java/latest

Then I need to find what java installations are available and symlink them to the above directories:

ll /usr/lib/jvm

I usually choose the latest directory avialable...ie:

drwxr-xr-x. 3 root root   16 Feb 12  2016 java-1.8.0-openjdk-1.8.0.71-2.b15.el7_2.x86_64

and then create a link to /usr/java/latest

ln -s /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.71-2.b15.el7_2.x86_64/jre/lib /usr/java/latest/lib
ln -s /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.71-2.b15.el7_2.x86_64/jre/bin /usr/java/latest/bin

I am trying to create an installation script that automates the above process without having to copy and paste the directory name for the symbolic link. Basically I want to parse the /usr/lib/jvm/ directory for the most recent (or any) available java directory. Then I want to take that and link the lib and bin directories within that directory to the /usr/java/latest directory. Thank you in advance for any type of advice.

like image 723
GJJ Avatar asked Jul 24 '26 11:07

GJJ


1 Answers

I am using the below to find the directory I need.

ls -F /usr/lib/jvm | grep / | sed '$!d' | sed 's:/*$::'
like image 152
GJJ Avatar answered Jul 26 '26 02:07

GJJ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!