Hot questions for Using Ubuntu in java home

Question:

I have installed tomcat7 on my Ubuntu machine. When I try to restart the server I get message to set JAVA_HOME but it is set in .bashrc

export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export CATALINA_HOME=/usr/share/tomcat7

Error:

omkars@<ubuntu_14.04>:~$ sudo service tomcat7 restart
[sudo] password for omkars: 
 * no JDK or JRE found - please set JAVA_HOME
omkars@<ubuntu_14.04>:~$ echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle

What could be missing ? Thanks.


Answer:

Now, its working!

Changes I have done are:

  • changed .bashrc as explained in the question.
  • changed /etc/init.d/tomcat7 to point to oracle Java8 which is missing here!

    JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-7-oracle **/usr/lib/jvm/java-8-oracle**"
    

Then,

root@omkars-Dell-System-Inspiron-N4110:~# sudo service tomcat7 restart 
 * Starting Tomcat servlet engine tomcat7                                [ OK ] 

Got a hint from this page: https://mifosforge.jira.com/wiki/display/MIFOSX/Install+Tomcat+7+on+Ubuntu+11.10+for+Mifos+X

Thanks

Question:

I am trying to install some software (Shibboleth) in Ubuntu 14.04. I already have Java 7 OpenJDK installed in /usr/lib/jvm/, and I have these lines in /usr/environment

JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
export JAVA_HOME

If I type echo $JAVA_HOME I correctly get /usr/lib/jvm/java-7-openjdk-amd64. However, when I try to install Shibboleth I always get Error: JAVA_HOME is not defined correctly. Cannot execute java.

Interestingly, if I type java command it works (it refers to /usr/lib/java which is a link to the right one). However, when I try to run bash bin/install.sh of Shibboleth, I get the JAVA_HOME error

I already tried setting JAVA_HOME to the jre folder with same result. Any ideas?


Answer:

Add both JAVA_HOME & PATH to your ~/.profile

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH

And, add following to your /etc/profile.d/java.sh

JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export JAVA_HOME
PATH=${JAVA_HOME}/bin:${PATH}
export PATH
JRE_HOME=/usr/lib/jvm/jre
export JRE_HOME
JAVA_OPTS="-XX:+AggressiveOpts -Xms256m -Xmx512m -XX:MaxPermSize=256m -XX:+DisableExplicitGC"
export JAVA_OPTS

For more info, Refer Documentation

Hope it helps.

Question:

I'm trying to get WSL to recognize my windows installed environmental variable of JAVA_HOME. I attached of what I have in my bashrc and what I have in my windows environmental variables along with outputs from cmd and bash.

What's at the end of my bashrc:

export JAVA_HOME="/mnt/d/Program Files/Java/jdk-11.0.1"
export PATH="/mnt/d/Program Files/Java/jdk-11.0.1/bin:$PATH"

CMD INPUT/OUTPUT:

C:\Users\jaall>javac --version
javac 11.0.1

BASH INPUT/OUTPUT:

myubuntu_name@DESKTOP-LUK3BII:~$ javac --version

Command 'javac' not found, but can be installed with:

sudo apt install default-jdk
sudo apt install openjdk-11-jdk-headless
sudo apt install ecj
sudo apt install openjdk-8-jdk-headless

I've been stuck on this for awhile and can't figure it out or find a working solution online. Thanks!


Answer:

As Biswapriyo suggested, you should use WSLENV.

  1. Open PowerShell. Then set JAVA_HOME to the path to your java installation.

  2. In your case, run setx JAVA_HOME "D:\Program Files\Java\jdk-11.0.1"

You should see a message that says "SUCCESS: Specified value was saved.

  1. Then run setx WSLENV "JAVA_HOME/p"

You should see the success message again.

  1. Type 'env' into your WSL bash prompt.

You should see JAVA_HOME correctly set at this point.

Note: If step 2 doesn't work, you might want to changing the path to JAVA_HOME to include the '\bin' folder.

Question:

I am trying to run Maven 3.5 on my Ubuntu 16.04 desktop VM. I installed JDK 8 and set $JAVA_HOME and added the path. Despite this, Maven cannot find it. Here is the output:

root@ubuntu:/# echo $JAVA_HOME
opt/jdk1.8.0_131/bin/java

root@ubuntu:/# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:opt/jdk1.8.0_131/bin:opt/apache-maven-3.5.0/bin

root@ubuntu:/# mvn -v
The JAVA_HOME environment variable is not defined correctly This environment variable is needed to run this program NB: JAVA_HOME should point to a JDK not a JRE

Any ideas?


Answer:

JAVA_HOME should point to the JDK/JRE installation directory rather than to the java executable. In your case, that seems to be /opt/jdk1.8.0_131/ (the leading / is important, in its absence every software will try to access an opt directory in its current working directory)

Then you can append $JAVA_HOME/bin to the PATH, which has correctly been done in your case but apparently does not matter to Maven.

Question:

I am new to ubuntu. I am trying to use java-8. Where I have already installed java-6 in my ubuntu machine. I just want to use java-8 from my terminal (for test purpose); not from all over my machine. I want java-6 remains for all other software like eclipse. I heard to to so we can ubuntu terminal to export. So I am trying to do this -

$ export JAVA_HOME=/usr/lib/jvm/jdk8
$ export PATH=$PATH:$JAVA_HOME

after doing this when I type in terminal the fllowing command -

$ java -version 

it gives -

java version "1.6.0_29" Java(TM) SE Runtime Environment (build 1.6.0_29-b11) Java HotSpot(TM) Server VM (build 20.4-b02, mixed mode)

I tried several ways but nothing is working for me.


Answer:

I think you are missing the bin directory name after the $JAVA_HOME. Try this -

 $ export JAVA_HOME=/usr/lib/jvm/jdk8
 $ export PATH=$JAVA_HOME/bin:$PATH  

Note: I have place the JAVA_HOME before PATH. That means the JAVA_HOME/bin is concatenated with the existing PATH where the JAVA_HOME/bin is placed at the beginning of the new PATH. If you place the JAVA_HOME/bin at the end of the current PATH then the JAVA_HOME/bin is concatenated at the end of the new PATH. In this case the older JAVA_HOME (if exist one, in your case the jdk-6) may found first at the new PATH variable and will get precedence. A lots of times I get wrong when I placed JAVA_HOME/bin at the end of the PATH. So add JAVA_HOME/bin at the beginning in this case.

Question:


Answer:

In shell while setting a variable there should be no space between the valirable name and = character. Just change

export PATH =$PATH:$JAVA_HOME/bin

to

export PATH=$PATH:$JAVA_HOME/bin

Question:

New to Linux ubuntu

sudo update-alternatives --config java

returns "There is only one alternative in link group java (providing /usr/bin/java) /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java"

Really I just wanna set the $JAVA_HOME because I think I'll use it later.

I think i have to copy (as in Ctrl+c) "/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java" and set it as the $JAVA_HOME but not sure if that's correct because of the "providing" statement mentioned above. I'm not sure what "providing" means. :(

also, how do I copy (Ctrl+c) the returned folder address?

Thanks in advance :)


Answer:

You do not need to set JAVA_HOME unless you want to ensure that a specific Java is the one you use. In your case, you only have one specific Java installed.

That said, if you really want to configure this, add the following lines to your ~/.bashrc file

JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/
export JAVA_HOME

If you are going to go this route, I suggest also adding to your PATH

PATH=${JAVA_HOME}/bin:${PATH}
export PATH

somewhere below the JAVA_HOME lines detailed above.

Question:

on a tutorial (related to a product) it is shown hot to set the JAVA_HOME environment variable on a Linux Ubuntu system, in this way:

echo "JAVA_HOME=\"/usr/lib/jvm/default-java\"" | sudo tee -a /etc/environment

I have some trivial doubts:

1) What exactly is the JAVA_HOME environment variable and for what is it used?

From what I have understand it is something like a link to the JVM setted into the operating system that is used from the servlet container\application server to know where the JVM is and so it can be used. Is this assertion true or am I missing something? Exist some other purpose of this environment variable?

2) In the tutorial it is shown that the path of this environment variable is:

/usr/lib/jvm/default-java

but into my system I have something different, infact into the /usr/lib/jvm/ path I have not the default-java directory but I have a path like this:

/usr/lib/jvm/java-8-oracle

that contains the following directories:

  • bin
  • db
  • include
  • jre
  • lib
  • man

and some other files.

What is the correct path to use for the settings of my JAVA_HOME environment variable?

3) What exactly does this section of the previous statment:

sudo tee -a /etc/environment

Tnx


Answer:

1: You are correct

2: It should point to the actual root folder of the jvm/jdk install, in this case /usr/lib/jvm/java-8-oracle

3: tee is a command to output the input both to a file and the command line, that -a option appends it to the file. So essentially it, as a super-user, appends the output of the previous command echo "JAVA_HOME=\"/usr/lib/jvm/default-java\"" to the file /etc/environment but also outputs it to the command line. Output should be, for you, exactly: JAVA_HOME="/usr/lib/jvm/java-8-oracle"

Question:

I'm trying ubuntu inside my mac docker environment for development. javac/gcc works fine, but when I try to use JNI to connect java and c program, I found a problem. I need to find the include file and libjvm.so file on my ubuntu docker image. But unfortunately I found the javac is actually:

root@4968756a1edd:~/mynet/mytest/build/jni# javac -version
javac 1.8.0_191

root@4968756a1edd:~/mynet/mytest/build/jni# ls -lrt `which javac`
lrwxrwxrwx 1 root root 23 Feb  6 07:38 /usr/bin/javac -> 
/etc/alternatives/javac

Well, in an ubuntu/centos VM installation, usually there's a directory for a jdk and everything (bin/lib/include) is under this directory. But in docker image, how can I find this jdk installation location and all those headers/libraries?


Answer:

In bash you can set env variables like this:

sudo -H gedit /etc/environment
JAVA_HOME=/path/to/java/folder

Question:

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?


Answer:

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.

Question:

birdmw@birdmw-thinkpad:~/Desktop/nlp/iepy$ sudo iepy --create iepy Environment variable JAVAHOME not defined.

I am having this problem with package IEPY. It is Django and Java related.

I feel like I have tried everything to set the JAVAHOME path but nothing works:

birdmw@birdmw-thinkpad:~/Desktop/nlp/iepy$ echo $JAVAHOME /usr/lib/jvm/java-8-oracle/bin/java birdmw@birdmw-thinkpad:~/Desktop/nlp/iepy$ echo $JAVA_HOME /usr/lib/jvm/java-8-oracle/bin/java birdmw@birdmw-thinkpad:~/Desktop/nlp/iepy$ which java /usr/lib/jvm/java-8-oracle/bin/java

sudo vim /etc/environment PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" JAVAHOME=/usr/lib/jvm/java-8-oracle/bin/java JAVA_HOME=/usr/lib/jvm/java-8-oracle/bin/java

birdmw@birdmw-thinkpad:~/Desktop/nlp/iepy$ sudo iepy --create iepy Environment variable JAVAHOME not defined. birdmw@birdmw-thinkpad:~/Desktop/nlp/iepy$ Of course it is, am I taking crazy pills?


Answer:

The longer answer has to do with the use of sudo. But to just get you going, you should/can use this:

JAVAHOME=/usr/lib/jvm/java-8-oracle/bin/java JAVA_HOME=/usr/lib/jvm/java-8-oracle/bin/java iepy --create iepy

If you have to use sudo, you can do:

sudo JAVAHOME=/usr/lib/jvm/java-8-oracle/bin/java JAVA_HOME=/usr/lib/jvm/java-8-oracle/bin/java iepy --create iepy

Question:

As the title suggested, I have Ubuntu, and I was trying to tun the command ./gradlew setupDecompWorkspace in the Minecraft Forge folder, but I got the following error at about 70%

Execution failed for task ':recompileMc'.

Unable to find a javac compiler; com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK. It is currently set to "/usr/lib/jvm/java-7-openjdk-amd64/jre"

While I have the JAVA_HOME variable set to the JDK and not the JRE, I confirmed it by running export in terminal, and the following was stated

declare -x JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"

Please help me with this problem!!


Answer:

"/usr/lib/jvm/java-7-openjdk-amd64/jre"

JRE stands for Java Runtime Enviroment. usually the one without the compiler.

it should be jdk, not jre

Also, I suggest installing jdk 8 if you are planning on making mods for 1.8+

http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html

Question:

I installed the SERPOSCOPE program on my Ubuntu 18.04 server. It needs Java to work, so I installed OpenJDK :

$ sudo apt install openjdk-8-jdk
$ java -version

openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

Here are the installation instructions. There is a comment about the Java folder but I did not understand what I had to do :

https://github.com/serphacker/serposcope

https://serposcope.serphacker.com/en/doc/install.html

The problem and there is a problem with Java and SERPOSCOPE refuses to start :

ubuntu@serp-example-com:~$ sudo systemctl status serposcope
● serposcope.service - LSB: serposcope rank checker
   Loaded: loaded (/etc/init.d/serposcope; generated)
   Active: failed (Result: exit-code) since Sun 2019-05-12 16:06:15 CEST; 7s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 9785 ExecStart=/etc/init.d/serposcope start (code=exited, status=1/FAILURE)

May 12 16:06:15 serp-example-com systemd[1]: Starting LSB: serposcope rank checker...
May 12 16:06:15 serp-example-com serposcope[9785]: Can't find JAVA_HOME, java seems not installed on this OS
May 12 16:06:15 serp-example-com systemd[1]: serposcope.service: Control process exited, code=exited status=1
May 12 16:06:15 serp-example-com systemd[1]: serposcope.service: Failed with result 'exit-code'.
May 12 16:06:15 serp-example-com systemd[1]: Failed to start LSB: serposcope rank checker.


ubuntu@serp-example-com:~$ journalctl -xe
May 12 16:06:02 serp-example-com groupadd[9636]: group added to /etc/gshadow: name=serposcope
May 12 16:06:02 serp-example-com groupadd[9636]: new group: name=serposcope, GID=1001
May 12 16:06:02 serp-example-com useradd[9641]: new user: name=serposcope, UID=111, GID=65534, home=/var/lib/serposcope, shell=/usr/sbin/
May 12 16:06:02 serp-example-com usermod[9647]: change user 'serposcope' password
May 12 16:06:02 serp-example-com chage[9652]: changed password expiry for serposcope
May 12 16:06:03 serp-example-com systemd[1]: Reloading.
May 12 16:06:03 serp-example-com systemd[1]: Reloading.
May 12 16:06:03 serp-example-com sudo[9593]: pam_unix(sudo:session): session closed for user root
May 12 16:06:07 serp-example-com sudo[9749]:   ubuntu : TTY=pts/0 ; PWD=/home/ubuntu ; USER=root ; COMMAND=/usr/sbin/ufw allow 7134
May 12 16:06:07 serp-example-com sudo[9749]: pam_unix(sudo:session): session opened for user root by ubuntu(uid=0)
May 12 16:06:08 serp-example-com sudo[9749]: pam_unix(sudo:session): session closed for user root
May 12 16:06:15 serp-example-com sudo[9782]:   ubuntu : TTY=pts/0 ; PWD=/home/ubuntu ; USER=root ; COMMAND=/bin/systemctl start serposcop
May 12 16:06:15 serp-example-com sudo[9782]: pam_unix(sudo:session): session opened for user root by ubuntu(uid=0)
May 12 16:06:15 serp-example-com systemd[1]: Starting LSB: serposcope rank checker...
-- Subject: Unit serposcope.service has begun start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit serposcope.service has begun starting up.
May 12 16:06:15 serp-example-com serposcope[9785]: Can't find JAVA_HOME, java seems not installed on this OS
May 12 16:06:15 serp-example-com systemd[1]: serposcope.service: Control process exited, code=exited status=1
May 12 16:06:15 serp-example-com sudo[9782]: pam_unix(sudo:session): session closed for user root
May 12 16:06:15 serp-example-com systemd[1]: serposcope.service: Failed with result 'exit-code'.
May 12 16:06:15 serp-example-com systemd[1]: Failed to start LSB: serposcope rank checker.
-- Subject: Unit serposcope.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit serposcope.service has failed.
-- 
-- The result is RESULT.
May 12 16:06:18 serp-example-com kernel: [UFW BLOCK] IN=ens3 OUT= MAC=fa:16:3a:c8:b3:fc:0a:c5:39:6b:41:e2:08:00 SRC=185.10.68.55 DST=51.8
May 12 16:06:23 serp-example-com sudo[9813]:   ubuntu : TTY=pts/0 ; PWD=/home/ubuntu ; USER=root ; COMMAND=/bin/systemctl status serposco
May 12 16:06:23 serp-example-com sudo[9813]: pam_unix(sudo:session): session opened for user root by ubuntu(uid=0)
May 12 16:06:23 serp-example-com sudo[9813]: pam_unix(sudo:session): session closed for user root

ubuntu@serp-example-com:~$ sudo JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64 systemctl status serposcope

● serposcope.service - LSB: serposcope rank checker
   Loaded: loaded (/etc/init.d/serposcope; generated)
   Active: failed (Result: exit-code) since Sun 2019-05-12 17:43:02 CEST; 9min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 10202 ExecStart=/etc/init.d/serposcope start (code=exited, status=1/FAILURE)

May 12 17:43:02 serp-example-com systemd[1]: Starting LSB: serposcope rank checker...
May 12 17:43:02 serp-example-com serposcope[10202]: Can't find JAVA_HOME, java seems not installed on this OS
May 12 17:43:02 serp-example-com systemd[1]: serposcope.service: Control process exited, code=exited status=1
May 12 17:43:02 serp-example-com systemd[1]: serposcope.service: Failed with result 'exit-code'.
May 12 17:43:02 serp-example-com systemd[1]: Failed to start LSB: serposcope rank checker.

Answer:

First find out the location of Java home with update-java-alternatives -l (the last part is the path to remember).

Then run systemctl edit serposcope and this should open an editor. Add the following lines:

[Service]
Environment="JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64"

Where the value from JAVA_HOME is the one from the first point.

Try to start your service with sudo systemctl status serposcope