I'm working with Ubuntu 12.04 LTS.
I'm going through the hadoop quickstart manual to make a pseudo-distributed operation. It seems simple and straightforward (easy!).
However, when I try to run start-all.sh I get:
localhost: Error: JAVA_HOME is not set.
I've read all the other advice on stackoverflow for this issue and have done the following to ensure JAVA_HOME is set:
In /etc/hadoop/conf/hadoop-env.sh I have set
JAVA_HOME=/usr/lib/jvm/java-6-oracle
export JAVA_HOME
In /etc/bash.bashrc I have set
JAVA_HOME=/usr/lib/jvm/java-6-oracle
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH
which java returns:
/usr/bin/java
java –version works
echo $JAVA_HOME returns:
/usr/lib/jvm/java-6-oracle
I've even tried becoming root and explicitly writing the in the terminal:
$ JAVA_HOME=/usr/lib/jvm/java-6-oracle
$ export JAVA_HOME
$ start-all.sh
If you could show me how to resolve this error it would be greatly appreciated.
I'm thinking that my JAVA_HOME is being overridden somehow. If that is the case, could you explain to me how to make my exports global?
I am using hadoop 1.1, and faced the same problem.
I got it solved through changing JAVA_HOME variable in /etc/hadoop/hadoop-env.sh as:
export JAVA_HOME=/usr/lib/jvm/<jdk folder>
The way to solve this problem is to export the JAVA_HOME variable inside the conf/hadoop-env.sh file.
It doesn't matter if you already exported that variable in ~/.bashrc, it'll still show the error.
So edit conf/hadoop-env.sh and uncomment the line "export JAVA_HOME" and add a proper filesystem path to it, i.e. the path to your Java JDK.
# The Java implementation to use. Required.
export JAVA_HOME="/path/to/java/JDK/"
Ran into the same issue on ubuntu LTS 16.04. Running bash -vx ./bin/hadoop showed it tested whether java was a directory. So I changed JAVA_HOME to a folder and it worked.
++ [[ ! -d /usr/bin/java ]]
++ hadoop_error 'ERROR: JAVA_HOME /usr/bin/java does not exist.'
++ echo 'ERROR: JAVA_HOME /usr/bin/java does not exist.'
ERROR: JAVA_HOME /usr/bin/java does not exist.
So I changed JAVA_HOME in ./etc/hadoop/hadoop-env.sh to
export JAVA_HOME=/usr/lib/jvm/java-8-oracle/jre/
and hadoop starts fine.
The way to debug this is to put an "echo $JAVA_HOME" in start-all.sh. Are you running your hadoop environment under a different username, or as yourself? If the former, it's very likely that the JAVA_HOME environment variable is not set for that user.
The other potential problem is that you have specified JAVA_HOME incorrectly, and the value that you have provided doesn't point to a JDK/JRE. Note that "which java" and "java -version" will both work, even if JAVA_HOME is set incorrectly.
extract from etc/hadoop/hadoop-env.sh
The only required environment variable is JAVA_HOME. All others are
optional. When running a distributed configuration it is best to
set JAVA_HOME in this file, so that it is correctly defined on
remote nodes.
This means its better and advised to set JAVA_HOME here.. even though the existing definition reads the JAVA_HOME variable. Perhaps its not getting the value of JAVA_HOME from previously set value... standard apache manual does not tell this :( :(
This error is coming from Line 180
if [[ -z $JAVA_HOME ]]; then
echo "Error: JAVA_HOME is not set and could not be found." 1>&2
exit 1
fi
in libexec/hadoop-config.sh.
Try echo $JAVA_HOME in that script. If it doesn't recognize,
Find your JAVA_HOME using this:
$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")
and replace the line
export JAVA_HOME=${JAVA_HOME}
in /etc/hadoop/hadoop-env.sh with JAVA_HOME you got from above command.
I also had faced the similar problem in hadoop 1.1
I had not noticed that the JAVA_HOME was commented in: hadoop/conf/hadoop-env.sh
It was
/#JAVA_HOME=/usr/lib/jvm/java-6-oracle
Had to change it to
JAVA_HOME=/usr/lib/jvm/java-6-oracle
regardless of debian or any linux flavor, just know that ~/.bash_profile belongs to specific user and is not system wide.
in pseudo-distributed environment hadoop works on localhost so the $JAVA_HOME in .bash_profile is no use anymore.
just export the JAVA_HOME in ~/.bashrc and use it system wide.
Check if your alternatives is pointing to the right one, you might actually be pointing to a different version and trying to alter the hadoop-env.sh on another installed version.
-alternatives --install /etc/hadoop/conf [generic_name] [your correct path] priority {for further check man page of alternatives}
to set alternatives manually,
alternatives --set [generic name] [your current path].
Change the JAVA_HOME variable in conf/hadoop-env.sh
export JAVA_HOME=/etc/local/java/<jdk folder>
echo "export JAVA_HOME=/usr/lib/java" >> $HADOOP_HOME/etc/hadoop/hadoop-env.sh
Notice: Do not use export JAVA_HOME=${JAVA_HOME} !
I put it on the first line of file ~/.bashrc, then it works well!
export JAVA_HOME=/usr/lib/jvm/default-java
Related
echo $JAVA_HOME
gives me/usr/lib/jvm/java-8-oracle
and I have export JAVA_HOME= /usr/lib/jvm/java-8-oracle in my /usr/local/hadoop/etc/hadoop/hadoop-env.sh.
However when I run /usr/local/hadoop/bin/hadoop I got the following error:
/usr/local/hadoop/etc/hadoop/hadoop-env.sh: line 25: export: `/usr/lib/jvm/java-8-oracle': not a valid identifier
Error: JAVA_HOME is not set and could not be found.
I thought I had my JAVA_HOME correctly set, anyone can tell me where I did wrong?
Thanks.
Remove that space between the equals sign and the path in your export. Shell scripting can be a little finicky about that kind of thing.
This Must happened for Multiple JAVA_HOME Defined please check it in .bashrc file or .profile
I am trying to set up Java and Hadoop on my Mac machine, and in doing so, I am using this command:
$ echo export “JAVA_HOME=$(/usr/libexec/java_home)” >> ~/.bash_profile
$ source ~/.bash_profile
However, when I type source ~/.bash_profile it gives me this error:
-bash: export: `“JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home”': not a valid identifier
Why is it saying this?
This would more correctly look like:
echo 'export JAVA_HOME="$(/usr/libexec/java_home)"' >> ~/.bash_profile
Note:
Standard ASCII quotes, not curly "smart quotes", are used.
Single quotes are used to ensure that the command substitution is not evaluated before the echo is run, but instead is added to your .bash_profile.
My issue
I am on a MAC OS & was getting a similar error I got the following.
java -version
# -bash: /Library/Java/JavaVirtualMachines/jdk-18.0.1.1.jdk/Contents/Home/bin/java: Bad CPU type in executable
For my ~/.bash_profile
I had the very end of my bash profile set as:
# set JAVA_HOME
JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-18.0.1.1.jdk/Contents/Home"
PATH="${JAVA_HOME}/bin:${PATH}"
export PATH
# set M2_HOME
export M2_HOME=""
PATH="${M2_HOME}/bin:${PATH}"
export PATH
Fix
I just needed to update it too:
# set JAVA_HOME
JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-18.0.1.1.jdk"
PATH="${JAVA_HOME}/bin:${PATH}"
export PATH
# set M2_HOME
export M2_HOME=""
PATH="${M2_HOME}/bin:${PATH}"
export PATH
I just had to remove the /Contents/Home from the JAVA_HOME variable.
Now when i run java -version i get:
# openjdk version "18.0.2" 2022-07-19
# OpenJDK Runtime Environment (build 18.0.2+9-61)
# OpenJDK 64-Bit Server VM (build 18.0.2+9-61, mixed mode, sharing)
This effected my attempt to build using terminal in the IDE of IntelliJ IDEA. I was trying to run my jar file and it initially was a deceiving error.
According to this mobilefirst tutorial, it mentioned:
You must have the JAVA_HOME environment variable set to your JDK directory.
For example:
Mac OSX: /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home
I've added this 2 lines in .bash_profile:
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
export PATH=$PATH:$JAVA_HOME/Contents/Commands
Is this correct?
Thanks.
in .bash_profile:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.xx/Contents/Home
Adding the below answer to help those who are looking for step by step instructions on how to setup Java_Home on a Mac.
Determine whether Java is installed by using the command below:
which java
You will something like this - /usr/bin/java
Next Step will be to determine the version of Java Installed by using the command below:
java -version
You will see something like java version "1.8.0_131"
Next step will be to get the location where the Java is installed:
cd /Library/Java
Under the Java folder, select the folder with the version that was displayed earlier:
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
Next check if Java_Home is setup to the correct location:
echo $JAVA_HOME
It will result in blank output if it is not already setup. If it returns the location, check if it points to the correct folder.
You can add or update the Java_Home using the below commands:
vi ~/.bash_profile
Navigate to the end of the file by pressing "Shift + g".
Now press "i" to get to insert mode.
Add the below lines in the bash_profile after replacing the path to the java home directory on your mac
# Setting Java_Home
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
Save this by pressing Esc followed by ":wq!"
Finally open a new terminal window and test the variable is setup correctly:
echo $JAVA_HOME
It should return the Java_Home path setup
If your default terminal is /bin/zsh (Z Shell) like in my case, then you should set these environment variable in ~/.zshenv file with following contents:
export JAVA_HOME="$(/usr/libexec/java_home)"
Similarly, any other terminal type not mentioned above, you should set environment variable in its respective terminal env file.
After saved the content into env file, restart terminal and call following commands:
echo $JAVA_HOME
It should display the full Java path.
Just a note to say this still works in OpenJDK version 11. As shown in the original question the java_home utility lives in /usr/libexec, which might not be on your $PATH. You can run the command directly in a terminal window, here's sample output too:
$ /usr/libexec/java_home -v 11
/Library/Java/JavaVirtualMachines/jdk-11.0.4.jdk/Contents/Home
And set JAVA_HOME to that value. Even better, wire your shell script's dot files as suggested in the original question by #user1872384, because that way your environment automatically keeps up with JDK upgrades as you install them.
Before marking this as duplicate, I went through these posts, but nothing helped.
'mvn' is not recognized as an internal or external command,
Getting -bash: mvn: command not found,
Can't access mvn command from command line?
Some are specific to windows and did not help. A couple of them on Mac OS X gave suggestions, that I tried but did not help.
What I tried (this is exactly what Maven suggests):
Extract the distribution archive, i.e. apache-maven-3.1.1-bin.tar.gz
to the directory you wish to install Maven 3.1.1. These instructions
assume you chose /usr/local/apache-maven. The subdirectory
apache-maven-3.1.1 will be created from the archive. In a command
terminal, add the M2_HOME environment variable, e.g. export
M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1. Add the M2
environment variable, e.g. export M2=$M2_HOME/bin. Optional: Add the
MAVEN_OPTS environment variable to specify JVM properties, e.g. export
MAVEN_OPTS="-Xms256m -Xmx512m". This environment variable can be used
to supply extra options to Maven. Add M2 environment variable to your
path, e.g. export PATH=$M2:$PATH. Make sure that JAVA_HOME is set to
the location of your JDK, e.g. export JAVA_HOME=/usr/java/jdk1.5.0_02
and that $JAVA_HOME/bin is in your PATH environment variable. Run mvn
--version to verify that it is correctly installed.
I see that on the terminal that I used for installation, it works fine. I do not have this issue. but when I tried on a new terminal, I get command not found.
I also added export PATH=$M2 to my .bashrc, I did source and then restarted the terminal, still it did not help.
can someone suggest how to make it available in all sessions of terminal?
Thanks
Try following these if these might help:
Since your installation works on the terminal you installed, all the exports you did, work on the current bash and its child process. but is not spawned to new terminals.
env variables are lost if the session is closed; using .bash_profile, you can make it available in all sessions, since when a bash session starts, it 'runs' its .bashrc and .bash_profile
Now follow these steps and see if it helps:
type env | grep M2_HOME on the terminal that is working. This should give something like
M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1
typing env | grep JAVA_HOME should give like this:
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
Now you have the PATH for M2_HOME and JAVA_HOME.
If you just do ls /usr/local/apache-maven/apache-maven-3.1.1/bin, you will see mvn binary there.
All you have to do now is to point to this location everytime using PATH. since bash searches in all the directory path mentioned in PATH, it will find mvn.
now open .bash_profile, if you dont have one just create one
vi ~/.bash_profile
Add the following:
#set JAVA_HOME
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
export JAVA_HOME
M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1
export M2_HOME
PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin
export PATH
save the file and type source ~/.bash_profile. This steps executes the commands in the .bash_profile file and you are good to go now.
open a new terminal and type mvn that should work.
Solutions above are good but they require ~/.bash_profile. /usr/local/bin is already in the $PATH and it can be confirmed by doing echo $PATH. Download maven and run the following commands -
$ cd ~/Downloads
$ tar xvf apache-maven-3.5.3-bin.tar.gz
$ mv apache-maven-3.5.3 /usr/local/
$ cd /usr/local/bin
$ sudo ln -s ../apache-maven-3.5.3/bin/mvn mvn
$ mvn -version
$ which mvn
Note: The version of apache maven would be the one you will download.
Here is what worked for me.
First of all I checked if M2_HOME variable is set env | grep M2_HOME. I've got nothing.
I knew I had Maven installed in the folder "/usr/local/apache-maven-3.2.2", so executing the following 3 steps solved the problem for me:
Set M2_HOME env variable
M2_HOME=/usr/local/apache-maven-3.2.2
Set M2 env variable
M2=$M2_HOME/bin
Update the PATH
export PATH=$M2:$PATH
As mentioned above you can save that sequence in the .bash_profile file if you want it to be executed automatically.
I got same problem, I tried all above, nothing solved my problem. Luckily, I solved the problem this way:
echo $SHELL
Output
/bin/zsh
OR
/bin/bash
If it showing "bash" in output. You have to add env properties in .bashrc file (.bash_profile i did not tried, you can try) or else
It is showing 'zsh' in output. You have to add env properties in .zshrc file, if not exist already you create one no issue.
The possible solution can be that maven is not installed in your mac system.
Use this command to install maven:
brew install maven
And, to verify, that it is successfully installed, run this command:
mvn -v
If it returns you maven version, then maven is successfully installed in your system.
steps to install maven :
download the maven file from http://maven.apache.org/download.cgi
$tar xvf apache-maven-3.5.4-bin.tar.gz
copy the apache folder to desired place $cp -R apache-maven-3.5.4 /Users/locals
go to apache directory $cd /Users/locals/apache-maven-3.5.4/
create .bash_profile $vim ~/.bash_profile
write these two command :
export M2_HOME=/Users/manisha/apache-maven-3.5.4
export PATH=$PATH:$M2_HOME/bin
7 save and quit the vim :wq!
restart the terminal and type mvn -version
I followed brain storm's instructions and still wasn't getting different results - any new terminal windows would not recognize the mvn command. I don't know why, but breaking out the declarations in smaller chunks .bash_profile worked. As far as I can tell, I'm essentially doing the same thing he did. Here's what looks different in my .bash_profile:
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
export PATH JAVA_HOME
J2=$JAVA_HOME/bin
export PATH J2
M2_HOME=/usr/local/apache-maven/apache-maven-2.2.1
export PATH M2_HOME
M2=$M2_HOME/bin
export PATH M2
You probably have 2 types of shell instances.
sh vs zsh.
Both can have different path defined.
Check your PATH environment variable by typing the below line in terminal
echo $PATH
To test you can change shell mode -
sh to zsh -> type zsh and press enter in terminal (notice $ changes to %)
zsh to sh -> type sh/bash and press enter in terminal (notice % changes to $)
In Both shell modes check for PATH env.
Make both same, or append path from other as needed.
Commands running in 1 shell and not in other would be sorted.
For some of you the cause might be using of other variables in the path to the maven directory. More details in the answer.
I have set JAVA_HOME correctly and when I echo it, I see the correct value:
$ echo $JAVA_HOME
/usr/lib/jvm/java-6-openjdk-amd64/
I have also put the JAVA_HOME value to the hadoop-env.sh.
$ grep JAVA_HOME conf/hadoop-env.sh
# The only required environment variable is JAVA_HOME. All others are
# set JAVA_HOME in this file, so that it is correctly defined on
export JAVA_HOME="/usr/lib/jvm/java-6-openjdk-amd64/"
Despite all of this, hadoop still shows the JAVA_HOME variable totally different. I dont know where it gets this value. Any suggestions?
$ hadoop noname -format
Warning: $HADOOP_HOME is deprecated.
/usr/bin/hadoop: line 320: /usr/lib/jvm/java-6-sun/bin/java: No such file or directory
/usr/bin/hadoop: line 390: /usr/lib/jvm/java-6-sun/bin/java: No such file or directory
I had the same problem on my Hadoop install as well. I found in /etc/hadoop/hadoop-env.sh JAVA_HOME was hardcoded to be /usr/lib/jvm/java-6-sun. I went ahead and changed it to ${JAVA_HOME} and that seemed to do the trick.
In case anybody faces the same problem, look if /etc/hadoop directory is created. If yes, then point $JAVA_HOME variable in /etc/hadoop/hadoop-env.sh to appropriate jvm path.
I was having " error /usr/bin/java/bin/java doesn't exist "
In ~/.bashrc I had JAVA_HOME set to /usr/bin/java. I saw in hadoop/etc/hadoop-config.sh that it was using $JAVA_HOME/bin/java; which explained that error. Only, it did not fix it to remove /bin/java. To find my answer, I investigated via
cd /usr/bin/java
ls -al
And I saw
lrwxrwxrwx 1 root root 46 Jul 22 16:01 /usr/bin/java -> /etc/alternatives/java
What I noticed most was the the left side of the arrow was Teal and the right side of the arrow was Green, in my bash prompt. I thought it might be a symlink. I did this again this time ls -al'ing (the -al was very important) symlinked location (see below), and noticed what looked like another symlink.
root#groovy:~# ls /etc/alternatives/java -al
lrwxrwxrwx 1 root root 46 Jul 22 16:01 /etc/alternatives/java -> /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
I took that value on the right of the arrow, and put it in ~/.bashrc
final configurations
~/.bashrc
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
export PATH=$PATH:$JAVA_HOME
hadoop/etc/hadoop/hadoop-env.sh
export JAVA_HOME=${JAVA_HOME}
hadoop/libexec/hadoop-config.sh
EXPORT JAVA_HOME=$JAVA_HOME/bin
Note that I installed the JDK to begin with via sudo apt-get install default-jdk
There are two hadoop-env.sh files: one in the conf subdirectory under your hadoop directory, and one under /etc/hadoop. You need to change $JAVA_HOME in both.
In $HADOOP_HOME/etc/hadoop/hadoop-env.sh set
export JAVA_HOME=/usr/bin
In $HADOOP_HOME/libexec/hadoop-config.sh look for and modify JAVA=$JAVA_HOME/bin/java to
JAVA=$JAVA_HOME/java
I am pretty sure this is not the ideal solution. but this is what I did:
I put echo statements all throughout /usr/local/hadoop/bin/hadoop to see when JAVA_HOME gets set to a statically (seems static, anyhow) defined path of /usr/lib/jvm/java-6-sun.
I can tell this happens pretty much right away. And I had no idea why this was happening. I installed java in /usr/local/jdk1.7.0_17 and correctly set up JAVA_HOME in my path and everything. funny thing, is I dont even have java 6 installed!
so here is the hacky part. I went to where it expected to find java-6-sun, and set a symlink to my java install
cd /usr/lib/jvm
sudo ln -s /usr/local/jdk1.7.0_17/ java-6-sun
then everything worked. extremely hacky I know, but maybe this post could help someone else.
I had the same problem, but for me it was different issue. The hadoop script was expecting /opt/hadoop/jdk1.0.7.40 as my Java home. But I set it as /opt/hadoop/jdk1.0.7_40. The underscore made the difference. Now it is working. May be this will be helpfull to someone
Dan
I find a funny solution:
if you echo $JAVA_HOME, you may get /usr/bin/java
echo export $JAVA_HOME=/usr/ >> conf/hadoop-env.sh
complicated your stuff guys ....
I have /usr/lib/java-1.8.0-openjdk_BLABLA
while hadoop wants /usr/lib/java-1.8.0-openjdk_YADIYADA
then I go:
cp -ar /usr/lib/java-1.8.0-openjdk_BLABLA /usr/lib/java-1.8.0-openjdk_YADIYADA
and it' s happy !
no way messing up with all this non-sense confs...