Nutch Error: JAVA_HOME is not set - java

I followed this tutorial http://saskia-vola.com/nutch-2-2-elasticsearch-1-x-hbase/ When I finally tried to run Nutch sudo bin/nutch inject urls I got this error
Error: JAVA_HOME is not set.
but when I echo JAVA_HOME it returns
/usr/lib/jvm/java-7-openjdk-amd64
and it is also in /etc/environment
JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
and also I added line to end of file ~/.bashrc
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
but it still returns this error. How can I fix it?

You are running the command as root user, so the environment variables the application sees are the one's visible for root user not your user. Just check that the root has a JAVA_HOME environment variable set or run the program as your user, if possible.
You can try sudo -E bin/nutch inject urls
As the sudo manual says,
-E, --preserve-env
Indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the user does not have permission to preserve the environment.

make sure that the full JDK is there not only the JVM. you can also override this by export JAVA_HOME=YOUR_PREFERED_JDK_PATH in .bashrc file in you home directory.

Probably you didn't set java path in /etc/environment. Try given command.
sudo vi /etc/environment
and then set Java path
JAVA_PATH=/give your java path here/
You can check java path by using $JAVA_HOME, and then use
sudo -E bin/nutch inject urls

Related

$JAVA_HOME path not sourced correctly in ~/bash_profile at login

Upon logging into my CentOS 7 VM, my $JAVA_HOME is always set to :
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64/jre, which is incorrect.
My ~/.bash_profile reads:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.144-0.b01.el7_4.x86_64/jre
export JAVA_HOME
PYCHARM_HOME=/opt/pycharm-community-2017.2.3/
export PYCHARM_HOME
ECLIPSE_HOME=/opt/eclipse
export ECLIPSE_HOME
export SPARK_HOME=/opt/spark
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$JAVA_HOME/bin:$SPARK_HOME/bin:$PYCHARM_HOME/bin:$ECLIPSE_HOME
export PATH
Sourcing .bash_profile each time I open a new terminal appears to correct the issue, but why is my $JAVA_HOME path defaulting to an old version on startup and not being set to the directory specified in .bash_profile?
Sourcing .bash_profile each time I open a new terminal appears to
correct the issue, but why is my $JAVA_HOME path defaulting to an old
version on startup and not being set to the directory specified in
.bash_profile?
You need to logout from current user and login again so environment variables changes take place.
May be useful
In Bash:
Bash as login shell will load /etc/profile, ~/.bash_profile, ~/.bash_login, ~/.profile in the order.
Bash as non-login interactive shell will load ~/.bashrc
Environment :
Use /etc/environment to permanently system wide (all users, all processes) set environmental variables for all users.
/etc/environment is a system-wide configuration file, which means it is used by all users. It is owned by root though, so you need to be an admin user and use sudo to modify it.
Suppose if you set foo="bar" variable foo will be accessible from all the user sessions. To test the variable output first source it
source /etc/environment
~/.profile is one of your own user's personal shell initialization scripts. Every user has one and can edit their file without affecting others.
/etc/profile and /etc/profile.d/*.sh are the global initialization scripts that are equivalent to ~/.profile for each user. The global scripts get executed before the user-specific scripts though; and the main /etc/profile executes all the *.sh scripts in /etc/profile.d/ just before it exits.
Also note,
The /etc/environment file sets the variable system wide for every user on login.
Commands in the bash_profile are is executed if the bash shell is opened by any user. So the variables would not be set unless a bash shell is opened at least one time.
Run ps in the interactive shell to make sure you're in bash.
Try bash -l after login and see if it fixes your problem.
Add set -x before JAVA_HOME=... to check if there's something wrong.
It worked for me!
In my case, The follwing caused the error:
export JAVA_HOME = /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home
The error was that there were spaces before and after the = . The error disappeared after those spaces were removed.
So the correct command is as follows:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home

spark-class: line 71...No such file or directory

I've installed Spark 2.1.1 on Ubuntu and no matter what I do, it doesn't seem to agree with the java path. When I run "spark-submit --version" or "spark-shell" I get the following error:
/usr/local/spark/bin/spark-class: line 71: /usr/lib/jvm/java-8-openjdk-amd64/jre/bin//bin/java: No such file or directory
Now obviously the "/bin//bin/java" is problematic, but I'm not sure where to change the configuration. The spark-class file has the following lines:
if [ -n "${JAVA_HOME}" ]; then
RUNNER="${JAVA_HOME}/bin/java"
I was originally using a version of Spark meant for Hadoop 2.4 and when I changed it to "RUNNER="${JAVA_HOME}" it would either give me the error "[path] is a directory" or "[path] is not a directory." This was after also trying multiple path permutations in /etc/environment
What I now have in /etc/environment is:
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/"
This is the current java setup that I have:
root#ubuntu:~# update-alternatives --config java
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
bashrc has the following:
export SPARK_HOME="/usr/local/spark"
export PATH="$PATH:$SPARK_HOME/bin"
Can anyone advise: 1) What files I need to change and 2) how I need to change them? Thanks in advance.
spark-class file is in the link, just in case:
http://vaughn-s.net/hadoop/spark-class
In the /etc/environment file replace
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/
with
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/
then execute
source /etc/environment
also RUNNER="${JAVA_HOME}/bin/java" should be kept as it is
Windows Environment:
Open Advanced system settings -> Environment Variables to set JAVA_HOME path, and the most common mistake is setting the path to JAVA folder:
JAVA_HOME: Directory-Name:\java
rather than setting it to JDK folder
JAVA_HOME: Directory-Name:\jdk
This is how it worked for me.

'mvn' is not recognized as an internal or external command, operable program or batch file error in Windows 10

I have read similar questions about this problem but it is not working anyways.
I've extracted maven 3.3.3 to D:\Maven (Java already installed and works fine) then added 2 system variables:
Variable
Value
M2
%M2_HOME%\bin
M2_HOME
D:\Maven
I've also appended next in the path:
%M2%
But it is still not working.
I can execute mvn -version from the D:\Maven\bin but can't do this from another directory.
Don't put extra space in your path after D:\Maven\bin; in D:\Maven\bin; D:\Program Files\NodeJS; Please don't make any space in path variable.
Normally, To set mvn in command line in windows :
Set JAVA_HOME property in system environment
eg. JAVA_HOME=C:\Program Files\Java\jdk1.8.0_65
Set M2_HOME property in system environment
eg. M2_HOME=D:\apache-maven-3.3.3
Finally add maven to PATH
;%M2_HOME%\bin; add this at the end of PATH property of system environment
Now Try mvn -version
Try to put full maven path upto bin like "C:\Users\ABC\Downloads\maven-2.0.5-bin\maven-2.0.5\bin" directly into path variable of os, then you will be able to understand where problem exists.
One mistake I did was, There will two environment variables section
One can be accessed via admin while the other one doesn't require any.
Please specify the paths in the second place
It will work for sure., also try echo %M2_HOME% to check whether you have configured correctly..before jumping to mvn install
Hope this helps for someone who has to use admin rights

Ubuntu now able to set java path

I have installed oracle jdk in /usr/lib/jvm/ and i have setted up path in etc/environment as
JAVA_HOME=/usr/lib/jvm/jdk1.7.0_51
PATH=$PATH:$JAVA_HOME/bin
But still when i am running javac, I am getting following error. The program 'javac' can be found in the following packages:
* default-jdk
* ecj
* gcj-4.6-jdk
* gcj-4.7-jdk
* openjdk-7-jdk
* openjdk-6-jdk
It means javac is not installed or java path has not setted properly, however i am able to see javac,java,jps and other programs in my /usr/lib/jvm/jdk1.7.0_51. I have searched enough about it but still not able to get solution of this problem.
The file /etc/environment is not a file executed by the shell (like a shell script); you cannot use $SOMETHING references in this file. Variables are not substituted in this file. So,
JAVA_HOME=/usr/lib/jvm/jdk1.7.0_51
PATH=$PATH:$JAVA_HOME/bin
the second line will not work like this. You have to put the exact path in.
JAVA_HOME=/usr/lib/jvm/jdk1.7.0_51
PATH=...:/usr/lib/jvm/jdk1.7.0_51/bin
The javac binary (and probably other java binaries) is/are not in your user's $PATH environment variable. There are several ways you can address this:
Add /usr/lib/jvm/jdk1.7.0_51/bin to your user's $PATH
environment variable. You can do this by adding a line similar to
the following in your user's .bash_profile:
export PATH=${PATH}:/usr/lib/jvm/jdk1.7.0_51/bin
You'll have to restart your terminal session for it to take effect.
Create symbolic links to the java binaries from some directory
that's already part of your path (such as /usr/bin)
sudo ln -s /usr/lib/jvm/jdk1.7.0_51/bin/java /usr/bin/
sudo ln-s /usr/lib/jvm/jdk1.7.0_51/bin/javac /usr/bin/
BTW: There are several other java executables in /usr/lib/jvm/jdk1.7.0_51/bin. see the symlink commands for java and javac above. You should run similar command for any other executables you may want to use.
Use the fully qualified path directly on the command line:
$ /usr/lib/jvm/jdk1.7.0_51/bin/javac
https://help.ubuntu.com/community/Java
have you tried this page? Its where I go when I need Java info. You may not have the one you installed set as default.
Could it be that you did not refresh the shell after change in path variable?
if you echo $PATH are the changes present?

default value of JAVA_HOME seems to be overwriting the value set by: /etc/profile.d/java.sh

I've created a file /etc/profile.d/java.sh that includes (among other things) the line of code: export JAVA_HOME=/usr/java/jdk1.6.0_30. However, when I log in via SSH or reboot the linux Centos 6.2 server, I always see:
[root#host3 /etc/profile.d]# echo $JAVA_HOME
/usr/local/jdk
This is a new installation and server, so there's not much else done. It seems that the java.sh file is executing upon reboot or SSH login, however, the value of JAVA_HOME is being overwritten by the default value of /usr/local/jdk somehow. There isn't even a directory jdk under /usr/local.
Any idea how to correct this? The value of JAVA_HOME needs to be set (as done in java.sh) for all users.
UPDATE 1:
I checked the /etc/profile file and searched for the text jdk as well as JAVA and neither were found. I also checked the /root/.bash_profile and it shows as follows:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
Also, if I source java.sh, everything gets set correctly. But if I reboot server, JAVA_HOME goes back to /usr/local/jdk.
Check the /etc/profile file or the .bash_profile/.profile in your home directory.
It appears that cPanel adds the following lines to the /etc/bashrc file to set the JAVA_HOME to it's default.
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/classes.zip
So, if you have cPanel installed, make sure you check this file as well.

Categories