I need to configure my Jenkins Server and I need to add Java path to Jenkins configuration.
yum install java-1.8.0-openjdk
However I'm new to lunix command, any suggestion please?
I dont know where yum install it!
See the validated answer!
try this if java command works
readlink -f $(which java)
They usually reside in /usr/lib/jvm. You can list them via ll /usr/lib/jvm. The value you need to enter in the field JAVA_HOME in jenkins is /usr/lib/jvm/java-1.8.0-openjdk.
Update
when I look at '/usr/lib/jvm' I get ...
What you see there is a list of symbolic links pointing to a similar target located in /etc/alternatives. In the end they all point to the same target. The difference is only the name which allows you to choose how explicit your choice if the target version shall be.
(Because java-1.8.0-openjdk is missing: Maybe you also need to install the package java-1.8.0-openjdk-devel.)
Here are the solution
# cd /opt/jdk1.7.0_79/
# alternatives --install /usr/bin/java java /opt/jdk1.7.0_79/bin/java 2
# alternatives --config java
# alternatives --install /usr/bin/jar jar /opt/jdk1.7.0_79/bin/jar 2
# alternatives --install /usr/bin/javac javac /opt/jdk1.7.0_79/bin/javac 2
# alternatives --set jar /opt/jdk1.7.0_79/bin/jar
# alternatives --set javac /opt/jdk1.7.0_79/bin/javac
# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
# export JAVA_HOME=/opt/jdk1.7.0_79
# export PATH=$PATH:/opt/jdk1.7.0_79/bin
Thanks to tecadmin
Try echo $JAVA_HOME or look in vi ~/.bash_profile
I am on Ubuntu and I have set the following in my ~/.bashrc file:
export JAVA_HOME=/opt/jdk1.8.0_91
export PATH=$JAVA_HOME/bin:$PATH
and then:
echo $JAVA_HOME
>/opt/jdk1.8.0_91
java -version
>java version "1.8.0_91"
>Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
>Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
at the first glance, the command sudo update-alternatives --config java was not showing my manually installed Java, so I installed it to the command with sudo update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_91 1.
Now, the command sudo update-alternatives --config java drops down the list of all Java versions being installed like that:
0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 auto mode
1 /opt/jdk1.7.0_51/bin/java 1 manual mode
* 2 /opt/jdk1.8.0_91 1 manual mode
3 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
4 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode
But switching between these using the prompt of the sudo update-alternatives --config java does not affect $JAVA_HOME and then $java -version.
My question is, what does sudo update-alternatives --config java exactly do after switching to another alternative with respect to the settings in the $JAVA_HOME$ variable?
It only changes a symlink located (on most distro I guess) at /etc/alternatives/java.
Absolutely NO change in the environment variable you set $JAVA_HOME is made.
First look at from where the command is found, you can do :
$which java
/usr/bin/java
The which command shows /usr/bin/java in my Debian distro. This file is a symlink which points to /etc/alternatives/java.
$ls -l /usr/bin | grep java
java -> /etc/alternatives/java
Then you follow the symlink :
$ls -l /etc/alternatives/java
/etc/alternatives/java -> /path/to/my/java/installation/1.x/bin/java
This shows that /etc/alternatives/java is another symlink.
When you do an update-alternatives on java, you just change this symlink target to another one.
Then, why doesn't the executed version change when you do the update-alternatives command ?
I guess it's because of the order the executables are found in $PATH.
Since you added a directory to the PATH environment variable, there are now two possible java executables : one in /usr/bin and the other in /opt/jdk1.8.0_9, but only the first one found will be taken into account when you'll type java commands.
And because you set
PATH=$JAVA_HOME/bin:$PATH
The first one will be found in $JAVA_HOME/bin aka /opt/jdk1.8.0_91 .
Because you made /opt/jdk1.8.0_9 appear before /usr/bin which is defined by default in the the PATH variable.
You can check it by typing in a terminal
$echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/path/to/my/java/installation/1.x/bin
You can see that my java/bin dir is located after the others defined in the PATH.
To correct this, you just have to concatenate $JAVA_HOME/bin after $PATH, like this :
PATH=$PATH:$JAVA_HOME/bin
This way you will be able to choose the default java executable from alternatives and the java exe found in $JAVA_HOME/bin will be discarded.
But to be consistent, in most cases you should choose the same java exe as in $JAVA_HOME/bin.
Java is an optional package on the latest versions of macOS.
Yet once installed it appears like the JAVA_HOME environment variable is not set properly.
With the Java optional package or Oracle JDK installed,
adding one of the following lines to your ~/.bash_profile file will set the environment variable accordingly.
export JAVA_HOME="$(/usr/libexec/java_home -v 1.6)"
or
export JAVA_HOME="$(/usr/libexec/java_home -v 1.7)"
or
export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"
or simply
export JAVA_HOME="$(/usr/libexec/java_home)"
Note: If you installed openjdk on mac using brew, run sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk for the above to work
Update: added -v flag based on Jilles van Gurp response.
/usr/libexec/java_home is not a directory but an executable. It outputs the currently configured JAVA_HOME and doesn't actually change it. That's what the Java Preferences app is for, which in my case seems broken and doesn't actually change the JVM correctly. It does list the 1.7 JVM but I can toggle/untoggle & drag and drop all I want there without actually changing the output of /usr/libexec/java_home.
Even after installing 1.7.0 u6 from Oracle on Lion and setting it as the default in the preferences, it still returned the apple 1.6 java home. The only fix that actually works for me is setting JAVA_HOME manually:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_06.jdk/Contents/Home/
At least this way when run from the command line it will use 1.7. /usr/libexec/java_home still insists on 1.6.
Update: Understanding Java From Command Line on OSX has a better explanation on how this works.
export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
is the way to do it. Note, updating this to 1.8 works just fine.
For me, Mountain Lion 10.8.2, the solution most voted does not work.
I installed jdk 1.7 via Oracle and maven from homebrew.
My solution is from the hadoop-env.sh file of hadoop which I installed from homebrew, too.
I add the below sentence in ~/.bash_profile, and it works.
export JAVA_HOME="$(/usr/libexec/java_home)"
This solution also works for OS X Yosemite with Java 1.8 installed from Oracle.
None of the above answers helped me. I suppose all the answers are for older OS X
For OS X Yosemite 10.10, follow these steps
Use your favorite text editor to open: ~/.bash_profile
//This command will open the file using vim
$ vim ~/.bash_profile
Add the following line in the file and save it ( : followed by "x" for vim):
export JAVA_HOME=$(/usr/libexec/java_home)
Then in the terminal type the following two commands to see output:
$ source ~/.bash_profile
$ echo $JAVA_HOME
In the second line, you are updating the contents of .bash_profile file.
Update for Java 9 and some neat aliases.
In .bash_profile:
export JAVA_HOME8=`/usr/libexec/java_home --version 1.8`
export JAVA_HOME9=`/usr/libexec/java_home --version 9`
Note, that for the latest version it is 9 and not 1.9.
Set active Java:
export JAVA_HOME=$JAVA_HOME8
export PATH=$JAVA_HOME/bin:$PATH
Some additional alias to switch between the different versions:
alias j8='export JAVA_HOME=$JAVA_HOME8; export PATH=$JAVA_HOME/bin:$PATH'
alias j9='export JAVA_HOME=$JAVA_HOME9; export PATH=$JAVA_HOME/bin:$PATH'
Test in terminal:
% j8
% java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
% j9
% java -version
java version "9"
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
EDIT: Update for Java 10
export JAVA_HOME10=`/usr/libexec/java_home --version 10`
alias j10='export JAVA_HOME=$JAVA_HOME10; export PATH=$JAVA_HOME/bin:$PATH'
EDIT: Update for Java 11
export JAVA_HOME11=`/usr/libexec/java_home --version 11`
alias j11='export JAVA_HOME=$JAVA_HOME11; export PATH=$JAVA_HOME/bin:$PATH'
The above didn't work for me with Amazon's EC2 tools, because it expects bin/java etc. underneath JAVA_HOME. /System/Library/Frameworks/JavaVM.framework/Home did work.
For OS X you can do:
export JAVA_HOME=`/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home`
On Mac OS X Lion, to set visualgc to run, I used:
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
The following worked for me. I'm using ZSH on OSX Yosemite with Java 8 installed.
The following command /usr/libexec/java_home emits the path to JDK home:
/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
In your ~/.zshrc,
export JAVA_HOME = "/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home"
for macOS Mojave 10.14.1 and JAVA 11.0.1
I set the profile as
export JAVA_HOME=$(/usr/libexec/java_home)
key in terminal this to confirm:
$JAVA_HOME/bin/java -version
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)
A better (more upgradable) way is to use the following:
/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
This should work with AWS also since it has bin underneath Home
Newer Oracle JVMs such as 1.7.0_21-b12 seem to install here:
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
My approach is:
.bashrc
export JAVA6_HOME=`/usr/libexec/java_home -v 1.6`
export JAVA7_HOME=`/usr/libexec/java_home -v 1.7`
export JAVA_HOME=$JAVA6_HOME
# -- optional
# export PATH=$JAVA_HOME/bin:$PATH
This makes it very easy to switch between J6 and J7
I Had to explicitly set it to the exact path on my Macbook air .
Steps followed:
try to echo $JAVA_HOME (if it's set it'll show the path), if not, try to search for it using sudo find /usr/ -name *jdk
Edit the Bash p with - sudo nano ~/.bash_profile
Add the exact path to JAVA Home (with the path from step 2 above)
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
Save and exit
Check JAVA_Home using - echo $JAVA_HOME
I am running MACOS MOJAVE - 10.14.2 (18C54) on a Macbook Air with JAVA 8
OSX Yosemite, ZSH, and Java SE Runtime Environment 8, I had to:
$ sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands /System/Library/Frameworks/JavaVM.framework/Versions/Current/bin
and in ~/.zshrc change JAVA_HOME to
export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/Current"
For Mac OS X 10.9 I installed the latest version of JRE from Oracle and then reset the JAVA_HOME to /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home.
I am sure there is a better way but this got me up and running.
hughsmac:~ hbrien$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
For Java 11 (JDK 11) it can be located with the following command:
/usr/libexec/java_home -v 11
Got the same issue after I upgrade my Mac OS and following worked for me:
cmd>vi ~/.bash_profile
Add/update the line for JAVA_HOME:
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_15.jdk/Contents/Home"
cmd>source ~/.bash_profile or open a new terminal
I think the jdk version might differ, so just use the version which you have under /Library/Java/JavaVirtualMachines/
If you are in need to have multiple versions of JDK under Mac OS X (Yosemite), it might be helpful to add some scripting for automated switching between them.
What you do is to edit your ~/.bash_profile and add the following:
function setjdk() {
if [ $# -ne 0 ]; then
removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'
if [ -n "${JAVA_HOME+x}" ]; then
removeFromPath $JAVA_HOME
fi
export JAVA_HOME=`/usr/libexec/java_home -v $#`
export PATH=$JAVA_HOME/bin:$PATH
fi
}
function removeFromPath() {
export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
}
setjdk 1.7
What the script does is to first remove other JDK versions in the PATH so that they won’t interfere with our new JDK version. Then it makes some clever use of /usr/libexec/java_home which is a command that lists installed JDK versions. The -v argument tells java_home to return the path of the JDK with the supplied version, for example 1.7. We also update the PATH to point to the bin directory of the newly found JAVA_HOME directory. At the end we can simply execute the function using
setjdk 1.7
which selects the latest installed JDK version of the 1.7 branch. To select a specific version you can simply execute
setjdk 1.7.0_51
instead. Run /usr/libexec/java_home -V to get more details on how to choose versions.
P.S. Do not forget to source ~/.bash_profile after you save it.
For Fish terminal users on Mac (I believe it's available on Linux as well), this should work:
set -Ux JAVA_8 (/usr/libexec/java_home --version 1.8)
set -Ux JAVA_12 (/usr/libexec/java_home --version 12)
set -Ux JAVA_HOME $JAVA_8 //or whichever version you want as default
This answer is related to Mountain Lion and not Lion. I needed to do this for the AWS Command Line Tools. According to the AWS docs, running which java returns /usr/bin/java.
So, I set JAVA_HOME=/usr in my .bashrc.
Apparently, /usr/bin/java is a symbolic link to /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java which makes it all work.
Update
As mentioned in the comment below, this JAVA_HOME value is not an ideal solution when the JAVA_HOME environment variable is to be used by things other than the AWS Command Line Tools. It works fine for the AWS Command Line Tools, though, as given in their docs.
for mac user .
java 8 should add
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
# JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
java 6 :
export JAVA_HOME=`/usr/libexec/java_home -v 1.6`
# JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
ref :http://qiita.com/seri_k/items/e978c1339ce51f13e297
For Mac Yosemite,
JDK 1.7.0_xx is using
$ ls -ltar /usr/bin/java
/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_xx.jdk/Contents/Home
Anyone using AUSKEY from the Australian Tax Office (ATO) should uninstall AUSKEY.
This sorted out my JAVA_HOME issues.
It is also no longer required for MAC users. Yah!
I'm using Fish shell on High Sierra 10.13.4 and installed Java via Brew.
It's not automatically set up so to set it correctly on my system I run:
set -U JAVA_HOME (/usr/libexec/java_home)
Just set java_home of 1.8 jdk version in netbeans.conf file:
/Applications/NetBeans/NetBeans 8.2.app/Contents/Resources/NetBeans/etc/netbeans.conf
uncomment line:
netbeans_jdkhome="path/to/jdk"
and set path to your 1.8 jdk, in my case:
netbeans_jdkhome="/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home"
This approach lays you to have several jdk versions on mac os
Handy command for knowing java home and other details.
java -XshowSettings:properties -version
and to know all java homes on your mac:
/usr/libexec/java_home -V
I have set all the requirement variables in the /etc/profile but when launching elasticsearch, it is still not find Java. How i can set the environment variable. That's my /etc/profile
PATH=$PATH:$HOME/bin
APPLICATIONS=$HOME/Applications
JAVA_HOME=$APPLICATIONS/jdk1.7.0_79
PATH=$JAVA_HOME/bin:$PATH
export APPLICATIONS
export JAVA_HOME
export PATH
Output of commands
[root#87500e63467f Applications]# echo $PATH
/root/Applications/jdk1.7.0_79/bin:/root/Applications/jdk1.7.0_79/bin:/root/Applications/jdk1.7.0_79/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/bin:/root/bin
[root#87500e63467f Applications]# echo $JAVA_HOME
/root/Applications/jdk1.7.0_79
[root#87500e63467f Applications]# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
error: "Read-only file system" setting key "vm.max_map_count"
Starting elasticsearch: which: no java in (/sbin:/usr/sbin:/bin:/usr/bin)
Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME
[FAILED]
in the error, it says that ""Starting elasticsearch: which: no java in (/sbin:/usr/sbin:/bin:/usr/bin)"", it means really java isn't in that path, but how come when I echo $PATH, it shows that the java is in the path ?
After reading the docs from ElasticSearch, I found that if you're running on Ubuntu or Debian, the package only ships with the OpenJDK because of licensing issues. To fix this Java path problem, I installed the following after installing ElasticSearch (as directed by the docs):
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
java -version
Then upon running sudo service elasticsearch start everything worked and I had no more Java path issues.
run the command
java -XshowSettings
search the entry java.home = /usr/java/jdk1.8.0_91/jre
export the java_home in your bash profile
export JAVA_HOME=/usr/java/jdk1.8.0_91/jre
or in /etc/profile to expand to all users
Specifically for OpenBSD6.0, add
export JAVA_HOME=/usr/local/jdk-1.8.0/
to your .profile.
This specific version of the jdk, and possibly the basic path itself is subject to change in subsequent and previous versions of OpenBSD, you have been warned.
To get it going - though not nice - you could setup a symbolic link to your java in /usr/bin (which is listed by elasticsearch to be seen):
ln -s /root/Applications/jdk1.7.0_79/bin/java /usr/bin/java
Make sure the path you have provided for JAVA_HOME is correct.
And why not keep it simple:
export PATH=$PATH:/path/to/jdk
try to set Java home to /jdk1.7.0_79/bin and see if that helps.
Simply add the below path in bashrc and profile file under /etc/ directory.
export JAVA_HOME=/path/to/java/jdk
export PATH=$JAVA_HOME/bin:$PATH
I noticed one file in the output called /etc/sysconfig/elasticsearch
this might do the trick, so I defined JAVA_HOME in this file like, and it works.
more u can get from here
Encountered the same issue while installing Elasticsearch 5 on a debian machine. That's how I installed Java 9:
su -
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
apt-get update
apt-get install oracle-java9-installer
I don't know if this is your particular situation, but working with ElasticSearch/Kibana/Logstash (ELK stack) the docs didn't work for me on Ubuntu 16.04. Putting content from this post together with several others, my solution was:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
# checking my work given 9 won't work with OSSEC you can use
# java -version
sudo usermod -a -G ossec logstash
sudo apt-get install logstash
sudo systemctl daemon-reload
sudo systemctl enable logstash.service
sudo systemctl start logstash.service
The end result for me on ubuntu 16.04 was
sudo java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
If you are working with wazuh, it is important to add the PPAs for their specific versions. I hope this helps.
you need set JAVA_HOME in the /etc/default/elasticsearch,like
cat /etc/default/elasticsearch
JAVA_HOME=/var/local/jdk1.8.0_151
the next start
/etc/init.d/elasticsearch start
ES running.
my OS ubuntu18.04.
If you are using "not installed" Java, check if your "elasticsearch" user has access to the defined by you JAVA_HOME directory and all parent directories. That was my problem..
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