Install Java 12 in Ubuntu 14 - java

I want to Install Java 11 or 12 on my Ubuntu 14 machine. As of now, I'm isntalling 12.
To Install, I've downloaded Java at below location and extracted too at same location.
/usr/lib/jvm
/usr/lib/jvm/jdk-12.0.1
After that, I've added JAVA_HOME path in environment file
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
JAVA_HOME="/usr/lib/jvm/jdk-12.0.1/"
export JAVA_HOME
But when I check java -version, It shows me below error
The program 'java' can be found in the following packages:
* default-jre
* gcj-4.8-jre-headless
* openjdk-7-jre-headless
* gcj-4.6-jre-headless
* openjdk-6-jre-headless
Try: sudo apt-get install <selected package
May I know please, What am doing wrong....?
Thanks

As correctly pointed out in the comments by RealSkeptic, the JAVA_HOME environment variable is not utilized by your shell to detect where the java runtime is located.
Try adding the following to the line to your environment file after export JAVA_HOME
export PATH=${JAVA_HOME}/bin:${PATH}
If your JAVA_HOME is set correctly it should be added correctly to your PATH

Related

WSL Bash isn't finding java in PATH

I have an export command in my .bashrc to add the path of the java.exe file to PATH. Right now, running echo $PATH gives me this at the end
/mnt/c/Program Files/Java/jdk-14.0.2/bin
This is exactly where the java.exe and javac.exe files are stored, but when I run something like
java -version I'm getting the Command 'java' not found error. What am I doing wrong here?
You have added the Windows version of the Java binaries to the Path. You use WSL to run Linux binaries. (WSL1 is a compatibility layer, WSL2 uses the Linux kernel).
You have two options:
Install Java in your WSL environment. For example on Ubuntu with following commands:
sudo apt update
sudo apt install openjdk-14-jdk
After installing Java it will be available in the search path.
You could also run the Windows version by calling java.exe (note the .exe) on the name. This way WSL would call the Windows version. (https://learn.microsoft.com/en-us/windows/wsl/interop#run-windows-tools-from-linux)
If you want to use the windows version of java for some reason you where almost there. Try this please :)
java.exe -version
Install java in wsl:
sudo apt-get -y install openjdk-14-jdk
check the version.
java –version
check the path to config JAVA_HOME.
sudo update-alternatives --config java
eg
/usr/lib/jvm/java-14-openjdk-amd64/bin/java.
edit environment file to add the path:
sudo nano /etc/environment
add declare and add the JAVA_HOME:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$JAVA_HOME/bin"
JAVA_HOME=/usr/lib/jvm/java-14-openjdk-amd64
save and check the path.
source /etc/environment
echo $JAVA_HOME
Output
/usr/lib/jvm/java-14-openjdk-amd64

Setting Java path using bash script CentOs 7

I'm trying to change the path of java_home to java-1.7.0 in a CentOS 7 machine which already has java-1.8.0 installed.
I uninstalled java-1.8.0, and used 
yum -y install java-1.7.0
to install java 1.7. However,
which java
command still points to java-1.8. How do I find the path of java 1.7 JRE in this case in order to set java_home using a bash script?
Thank you,
Try setting JAVA_HOME with the new java path(eg. '/usr/local/java1.7/jdk').
export JAVA_HOME=/usr/local/java1.7/jdk
Then add the JAVA_HOME/bin to PATH variable.
export PATH=$JAVA_HOME/bin:$PATH
By default java will get installed in the ' /usr/lib/jvm ' location.
So, try ls command in this path to find the required java version.
cd /usr/lib/jvm
ls
Use this path to set the JAVA_HOME.

How to compile and run .java files in ubuntu?

I have Ubuntu 13.04 32-bit installed on my system.
I downloaded Java SE Development Kit 7 from here with the extention .tar.gz
I used the command tar xvfz Downloads/jdk-7u51-linux-i586.tar.gz to uncompress the downloaded file in my home directory i.e /home/computer/
I am able to compile and run java program using Bluej IDE. It is working fine.
I used the command jdk1.7.0_51/bin/java -jar Downloads/bluej-310.jar to install bluej IDE.
But I also want to compile and run java programs using the terminal in Ubuntu.
When I type the command java -version I get the message
The program 'java' can be found in the following packages:
* default-jre
* gcj-4.6-jre-headless
* gcj-4.7-jre-headless
* openjdk-7-jre-headless
* openjdk-6-jre-headless
Try: sudo apt-get install <selected package>
Can anyone please help me out.
You can either install openjdk-7-jdk or add the bin directory of your downloaded distribution to your PATH variable and make it permanent by doing it in the configuration file of your shell. (Most likely .bash_profile in your home directory).
The easiest is probably sudo apt-get install openjdk-7-jdk (and then you can delete the one you downloaded).
I suggest that follow the instructions on https://help.ubuntu.com/community/Java. I think it's a lot more easier if you focused on the section regarding openjdk than sections on oracle java 7 than IBM 4. You may use the ubuntu software center app to locate the packages and install them rather than using the terminal.
You haven't completely installed java.. You are attempting to run the bash command
$java
and wherever you have extracted the jre, it isn't in your $PATH...
You must add it to your path like so:
$export PATH=$PATH:/home/computer/%THE_JAVA_DIR_THAT_YOU_INSTALLED%
or better yet,
get rid of the stuff you extracted and do this:
$sudo apt-get install openjdk-6-jre
It can save you a bit of a hassle to use Ubuntu's apt-get to install programs whenever possible
================EDIT
if ~/.profile doesn't exist, create it
Add the following lines in your .profile file in your home directory (using vi ~/.profile):
PATH=$PATH:/home/me/play
export PATH
Then, for the change to take effect, simply type in your terminal:
$ . ~/.profile

Java home in etc/enviroment in Ubuntu

Cannot set JAVA_HOME in /etc/enviroment with JAVA_HOME="/home/syncsys/bin/jdk1.7.0_10/"
The command echo $JAVA_HOME gives me /home/syncsys/bin/jdk1.7.0_10/ but it's not a correct Java HOME or I need something else?
I dont want bashrc or profile (some issues). Only /etc/enviroment and a way to eliminate the need of reboot after /etc/enviroment updates.
My /etc/envirment :
JAVA_HOME="/home/syncsys/bin/jdk1.7.0_10"
PATH=$JAVA_HOME:$PATH
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
some commands to test :
syncsys#sync-pc:~$ JAVA_HOME=/home/syncsys/bin/jdk1.7.0_10
syncsys#sync-pc:~$ export JAVA_HOME
syncsys#sync-pc:~$ PATH=$JAVA_HOME:$PATH
syncsys#sync-pc:~$ export PATH
syncsys#sync-pc:~$ java -version
The program 'java' can be found in the following packages:
* default-jre
* gcj-4.6-jre-headless
* gcj-4.7-jre-headless
* openjdk-7-jre-headless
* openjdk-6-jre-headless
update :
$ cat /etc/environment
JAVA_HOME="/home/syncsys/bin/jdk1.7.0_10"
PATH="$JAVA_HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
syncsys#sync-pc:~$ java -version
The program 'java' can be found in the following packages:
--------(solved) -------- Working sample that is now ok for me.
$ cat /etc/environment JAVA_HOME="/home/syncsys/bin/jdk1.7.0_10" PATH="/home/syncsys/bin/jdk1.7.0_10/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin‌​:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
I have read a lot of tutorials and similar forum posts for this but it's not working.
aha! I see the problem...
your JAVA_HOME is correct (if the path is pointing to your JDK, I hope so). The problem is you should change
PATH=$JAVA_HOME:$PATH
into
PATH=$JAVA_HOME/bin:$PATH
because the executable file "java" is not in your JAVA_HOME, it sits in JAVA_HOME/bin
You can install a progam called "galternatives" that will give you a visual representation of your alternatives symlinks to your java binaries.
Of course, you could probably set the JAVA_HOME separately (as an override) in a shell script like so:
JAVA_HOME=/any/location/i/want
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
Try in your shell:
export JAVA_HOME=/etc/environment
if working, edit your .bash_profile file and add this line again for every session
I had the same problem, this is my solution:
$] uname -a
Linux ******* x86_64 x86_64 x86_64 GNU/Linux
=> downloading a bin :jdk-6u45-linux-x64.bin
=> In my installation location
$]chmod u+x jdk-6u45-linux-x64.bin
$]./jdk-6u45-linux-x64.bin
...
Done
$]cd jdk1.6.0_45/jre/bin
$]./java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
It works..
1/ check your server configuration
2/ verify the owner of diretories after unpackaging.
2/ use binary pacquage .bin
Regards.
Richy.

Set Java environment variable problem on ubuntu

I got a message "No Java virtual machine could be found from your PATH
environment variable. You must install a VM prior to
running this program." Does anyone know how set up it correctly? Thanks!
If you install Java the Ubuntu way, you won't have to add it to the PATH yourself.
First, install Java from the Ubuntu repository:
sudo apt-get install sun-java6-jre
There are several other packages: sun-java6-jdk for the JDK, sun-java6-plugin for the browser plug-in etc.
Use Ubuntu's alternatives mechanism to select Sun Java 6 as the default version of Java that you want to use:
sudo update-alternatives --config java
This will present you with a menu where you can choose which version of Java you want to use by default (you can have multiple Java versions installed at the same time on your system).
See: https://help.ubuntu.com/community/Java
As the error message says, this looks like you have not set your PATH or JAVA_HOME environment variable correctly.
can you execute java from the command line? Try:
$ java -version
or
$ dpkg -L sun-java6-jre
Provided your are using debian or some derivative of it, if the "dpkg ..." command gives you any useful output, you should set the JAVA_HOME to the location of the installation directory, for instance
export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.10
export PATH=$PATH:$JAVA_HOME
and you should be able to get java running.
First make sure you have the path to your java binaries.
locate javac
This will return a list of all locations matching "java". Look for something like "/usr/lib/jvm/java-6-sun-1.6.0.11".
Open /etc/environment with a text editor and add the following. Make sure you set JAVA_HOME to the actual path of the java installation directory you just found:
export JAVA_HOME="/usr/lib/jvm/java-6-sun-1.6.0.11"
export PATH="$PATH:$JAVA_HOME/bin"
I think that you need to install this package
sudo apt-get install sun-java5-bin
also check this
> #!/bin/bash
> # Init Script for j2re
> #This goes in /etc/profile.d
>
> JAVA_HOME=/usr/java/j2reVERSion
> PATH=$JAVA_HOME/bin:$PATH
>
> export JAVA_HOME PATH

Categories