Trying to get OpenJDK 17 installed for Pufferpanel. User pi can do java -version fine however Pufferpanel gets bash: java: command not found
My /etc/profile and /etc/profile.d/java.sh have these lines:
#JAVA
export JAVA_HOME="/usr/lib/jvm/jdk-17.0.1+12"
export PATH=$JAVA_HOME/bin:$PATH
In addition JAVA_HOME="/usr/lib/jvm/jdk-17.0.1+12" is set in /etc/environment
Full permissions have been given for java.sh and the JAVA_HOME folder with chmod 777. The user pufferpanel now can run the script however the error stays the same: bash: java: command not found.
Trying some things out and found this:
pufferpanel#raspberrypi:/home/pi$ whereis java
java: /usr/share/java
Meanwhile pi gives this output:
pi#raspberrypi:~ $ whereis java
java: /usr/share/java /usr/lib/jvm/jdk-17.0.1+12/bin/java
Good news is that Java does run as the user pufferpanel:
pufferpanel#raspberrypi:/usr/lib/jvm/jdk-17.0.1+12/bin$ ./java -version
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment Temurin-17.0.1+12 (build 17.0.1+12)
OpenJDK Server VM Temurin-17.0.1+12 (build 17.0.1+12, mixed mode, sharing)
My guess is that PATH is getting overwritten somewhere, just don't know where.
If there are easier ways to install Java that is higher than version 16 just to get Minecraft to work, please tell me!
What you are doing is fine, but you should probably create a custom.sh shell script in /etc/profile.d/
As for environment variables, like JAVA_HOME, they should go in /etc/environment
Setting the PATH in ~/.bashrc worked out, copied java.sh and pasted it in. Couldn't find ~/.bashrc at first, but this helped to figure that out.
As Pufferpanel is a different matter, I'm marking this the answer to my question which was getting Java to work as an user.
Related
First, I'm using CentOS v6.1
I installed openjdk 8 and extracted it.
I set $JAVA_HOME, $JRE_HOME $PATH in ~/.bash_profile like below.
export PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME=/home/software/jdk8u222-b10
export JRE_HOME=/home/software/jdk8u222-b10/jre
I've also used source ~/.bash_profile in command line.
But when I type $ /home/software/jdk8u222-b10/bin/java -version or java -version,
it shows nothing to me even 'not found' errors. => image
How can I solve this problem?
I think it is not an environment path problem
When I directly execute jdk/bin/java file, it shows nothing to me.
It was server-side problem.
Old version of glibc and java was conflicted.
After upgrade glibc, the conflict did not occurred.
I recently installed Java but when I open the command line and I enter:
java -version
I get back:
C:\Users\Tim>java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
But when I enter:
javac -version
I get back:
C:\Users\Tim>javac -version
'javac' is not recognized as an internal or external command,
operable program or batch file.
I added the following line to the end of my path in environment variables:
;C:\Program Files\Java\jdk1.8.0_60\bin;
I installed this version:
jdk-8u60-windows-x64.exe
I use Windows 10. I have sought out multiple sources for help but none of them seem to be working. I think I've installed the right package as the name is JDK, it is for Windows on a 64 machine and java is found, but the compiler is not. I'm trying to train on Java now, but I'm stuck here and can't go much further until I iron this out. I appreciate any help. Thank you.
You missed some steps. Go to variable environment and do the following:
System Variables:
Edit path variable adding the following:
;C:\ProgramFiles\Java\Java_version\bin
Create a new variable. Its name will be classpath and its value will be:
;C\ProgramFiles\Java\Java_Version\src.zip
User Variables :
Create a variable called path, its value will be:
C:\ProgramFiles\Java\Java_verson\bin
Create a variable called classpath , its value will be:
C\ProgramFiles\Java\Java_Version\src.zip
I had that problem.. the solution is to remove all spaces from the java path. So instead of having it located at:
JAVA_HOME = C:\Program Files\Java\jdk1.8.0_60
move the jdk folder to,
for example: JAVA_HOME = C:\Java\jdk1.8.0_60
Then add the following line to the end of path in environment variables:
C:\Java\jdk1.8.0_60\bin;
it worked for me :)
I had installed java a while ago on my RHEL machine. Now, I'm trying to run a program that requires the JAVA_HOME variable to be set. What is the best way to figure out the installation directory of my java installation and then set JAVA_HOME? Here are the results of running java- version:
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
I have a /usr/lib/jvm directory, but it is empty.
RHEL uses alternatives subsystem to manage java installations. You can have
multiple versions of java installed, but only one is active at a time.
This means that running which java doesn't provide useful information. The
output would be the same no matter which java installation is selected via
alternatives. Running readlink -f $(which java) (as already suggested in
other comment) or using asking alternatives alternatives --display java would
be better.
See example from RHEL 6 machine with OpenJDK installed (which is shipped with
RHEL):
[root#example ~]# which java
/usr/bin/java
[root#example ~]# readlink -f $(which java)
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64/jre/bin/java
[root#example ~]# alternatives --display java | head -2
java - status is manual.
link currently points to /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
Note that enviroment variable JAVA_HOME is not defined anywhere by default,
you would need to define it yourself in .bashrc of user which requires it.
In previous example, correct value of JAVA_HOME would be
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64.
See details in Install OpenJDK
documentation, search for section "Optional: Set the JAVA_HOME environment variable".
First, try echo $JAVA_HOME from the command line. Since java is on your path already, JAVA_HOME may be set.
What is the best way to figure out the installation directory of my java installation
Running the command which java will point you to where java is installed.
and then set JAVA_HOME
You can edit ~/.bashrc, ~/.bash_profile, or /etc/profile to set JAVA_HOME. Setting it in ~/etc/profile will set it system wide, and this is probably not what you want. Say for the sake of example the output of which java is /opt/jdk_1.7.0_25, then you'd just add export JAVA_HOME=/opt/jdk_1.7.0_25 to ~/.bashrc or ~/.bash_profile and then run source ~/.bashrc (or source ~/.bash_profile if you set it there).
Note that in this case, java is on the PATH but in some cases you'd need to add export PATH=$PATH:$JAVA_HOME/bin to add the JAVA_HOME variable to the PATH.
readlink command will show you full path of symbolic link:
readlink -f `which java`
The best you can do is avoid Red Hat's java altogether.
Get your java from Oracle and put it in /opt.
Then just create symlink /opt/java -> /opt/jdk-someversion, and create /etc/profile.d/java.sh containing
#!/bin/sh
export JAVA_HOME=/opt/java
export PATH=$JAVA_HOME/bin:$PATH
Then, to change system-wide java, just change symlink in opt.
To use multiple java versions, use scripts like the above with appropriate JAVA_HOME.
Furthermore, /sbin/service script used to run /etc/init.d scripts will rip off environment variables - executes env -i explicitly. So i.e. your tomcat will not get JAVA_HOME, you'll have to create setenv.sh in $CATALINA_BASE/bin.
Drawback to this approach is you don't get java updates from Red Hat.
I found a way to combine the above so that I can programmaticly set JAVA_HOME.
export JAVA_HOME=$(dirname $(readlink -f $(which java))|sed 's^jre/bin^^')
On Ubuntu, returns /usr/lib/jvm/java-8-openjdk-amd64/.
On CentOS7, returns /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.201.b09-2.el7_6.x86_64/.
This can be added to a Makefile with
JAVA_HOME = $(shell dirname $$(readlink -f $$(which java))|sed 's^jre/bin^^')
This is much safer than exporting a hardcoded path and is more portable.
At least on RHEL 7, alternatives sets up a slave link for java_sdk at:
/etc/alternatives/java_sdk/
This is a symlink to the root of the SDK installation.
For me worked to change link in
/etc/alternatives for:
java -> /app/java/jdk8u222-b10/jre/bin/java
I know this is old java, but this server was neglected in our company.
The version of Java I have installed on my machine is:
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.11.90) (amazon-62.1.11.11.90.55.amzn1-x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
To set the path of JAVA_HOME, I wrote the following command in the ~/.bashrc file:
export JAVA_HOME=/usr/lib/jvm/default-java/
The command echo $JAVA_HOME gives the output /usr/lib/jvm/jre. I am assuming this is the wrong path, or am I wrong ?
And these are the files I have in the directory /usr/lib/jvm
java-1.6.0-openjdk-1.6.0.0.x86_64
jre
jre-1.6.0
jre-1.6.0-openjdk.x86_64
jre-openjdk
You should try doing the same using ~/.bash_profile , and ~/.profile as well... Then logoff and login, and see if it works using java --version
If files don't exist, then create them, add the export, and give them execution permissions using chmod +x .profile .bash_profile
It seems that maybe default-java is a symbolic link to all versions of java installed on your machine. Have you tried setting it to a specific java jdk bin?
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/
Check your javac program path using:
whereis javac
In debian based distributions use
sudo update-alternatives --display javac
To find out where your javac program resides, also (if you have several jdk's installed) update-alternatives lets you change the default javac
Update your JAVA_HOME in your ~/.bashrc and then type: source ~/.bashrc, then print again echo $JAVA_HOME, the change should apply immediately
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.