Trouble in Setting Java Environment Path on Ubuntu (libjvm.so: cannot open shared object file: No such file or directory)

StackOverflow https://stackoverflow.com/questions/18326412

Question

Found the solution!

Ubuntu by default ignore the command "RD_LIBRARY_PATH" therefore I need to add those codes in ".bashrc" instead of "/etc/environment" or .profile.

it now work perfectly fine!


I am trying to run a program that reads Java method from C/C++ code. (I made it on Windows successfully, now, I am working on Linux)

I made it successfully compiled and run on Ubuntu, however, the problem is.. Whenever I try to run the program, I have to type following commands on terminal..

source /etc/environment
./invoke #program name is invoke

If I do not type "source /etc/environment" every time I boot my PC, the error message I get is...

error while loading shared libraries: libjvm.so: cannot open shared object file: No such file or directory

Ok. Here is what I added in /etc/environment

export PATH="$PATH:/usr/lib/jvm/jdk1.7.0_25_x64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_25_x64
export LD_LIBRARY_PATH=$JAVA_HOME/jre/lib/amd64:$JAVA_HOME/jre/lib/amd64/server

What I want is that, as you know, I want to run the program without typing "source /etc/environment". I also tried typing those PATHs on /etc/profile, but result was same... I should type "source /etc/profile" every time I reboot my PC..

How to make it permanently applied to whole range of System without typing "source /etc/environment" stuffs everytime I boot?

if you need to see source code of the program, here is downloadable address: http://cfile237.uf.daum.net/attach/247819495212DF1C07B9EB

Was it helpful?

Solution 4

Found the solution!

Ubuntu by default ignore the command "RD_LIBRARY_PATH" therefore I need to add those codes in ".bashrc" instead of "/etc/environment" or .profile.

it now work perfectly fine!

OTHER TIPS

This worked for me:

For x86:

export LD_LIBRARY_PATH=/usr/lib/jvm/default-java/jre/lib/i386:/usr/lib/jvm/default-java/jre/lib/i386/server

For x86_64

export LD_LIBRARY_PATH=/usr/lib/jvm/default-java/jre/lib/amd64:/usr/lib/jvm/default-java/jre/lib/amd64/server

I had the same problem of setting the path(permanently) however I was using Red Hat, If you look change PATH permanently on Ubuntu it might help you. There was a file on Red Hat .profile that once you add your exports statements, they will get loaded when the computer starts. :) There should be the kind of file for ubuntu

export     PATH="$PATH:/usr/lib/jvm/jdk1.7.0_25_x64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"

export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_25_x64

Put "-Djava.library.path=FULL_PATH_HERE/jre/lib/amd64" as a JVM option in your C code.

Edit the full_path_here part.

The path is allowed to be relative, but I don't think you can use $JAVA_HOME as a placeholder for the environment variable.

  1. add the path of the missing libraries in the file /etc/ld.so.conf
  2. execute the following command: ldconfig this way, you'll add the new libraries to the default ones.
  3. To check whether the new libraries have been linked, execute the following command: ldconfig -p to have the list of libraries currently linked by default.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top