$JAVA_HOME variable changes with each new terminal - java

I recently installed Jdk1.8 on my machine. Everything went well and I made it work. After that I edited my /etc/profile file in order to set the new Java path. I edited the following line:
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk.x86_64
and then I executed
source /etc/profile
Here again everything went fine and I could see the changes on the terminal.
Problem is:
Everytime I open a new terminal I need to do
source /etc/profile
or else JAVA_HOME would have its old value.
Solution please? Thank you

If your username is 'test', then create a file called /home/test/.profile if it does not exist, and add your export command there.

Related

How to set environment variables permanently in Mac OS 10.15.6?

I have tried all approaches I can find online, but none of them works.
I want to set JAVA_HOME and PATH environment variables permanently, so that in IntelliJ I can issue commands like "mvn".
I have written my script into .bash_profile as shown below:
screenshot
But after I restarted my Mac and issued echo $JAVA_HOME, the output is still empty.
I also tried launchd.conf as said in this answer, but it didn't work either.
Could someone help me here?
Thanks in advance!
For osx add this in your ~/.profile or if you are using zsh inside ~/.zshrc
export JAVA_HOME=/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home
restart your terminal or simply apply your changes
source ~/.profile
refer this to know more about related to this question
& also refer this to know more about installation process of Amazon Corretto 8.
If you are using zsh you can import .profile config inside ~/.zprofile
emulate sh
. ~/.profile
emulate zsh
Check your enviroment variables with
env
then check if your config files are in the right directory. Read /etc/profile e.g.
nano /etc/profile
There can you find the path to bashrc file

JAVA_HOME is not set currently. Please set JAVA_HOME in mac

JAVA_HOME is not set currently. Please set JAVA_HOME. I want to run appium programs but its throwing this weird error
Even java_home path not displaying in terminal. Currently displaying blank
My bash profile
JAVA VERSION Is also getting displayed
try the following command:
vim .bash_profile (do you see export JAVA_HOME=$(/usr/libexec/java_home) under the file) ?
If not then you need to add it there.
If already added then run source .bash_profile, it reloads the file. And the path is set.
The first bash line is incorrect.
export JAVA_HOME=$(/usr/libexec/java_home)
Should be:
export JAVA_HOME=/usr/libexec/java_home

./d2j-dex2jar.sh Not found

I have installed all the files. sh but I keep giving this error I can do?
enter image description here
I had the same issue, setting JAVA_HOME as usual won't do unfortunately. You need to set the java binary to be accessible anywhere in the terminal by adding it to your $PATH like so:
export PATH=$PATH:$JAVA_HOME/bin
Then it should work fine :)

setting JAVA_HOME to the JDK location mac osx 10.9.5

I followed this thread to solve my problem, I have the same problem with a different version of JDK and for some reason it didn't work. I still get -bash: JAVA_HOME: command not found when I type JAVA_HOME to my terminal.
I have JDK1.8.0.45 located at Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home which I can access with /usr/libexec/java_home
Using
echo "export JAVA_HOME=/usr/libexec/java_home" >> ~/.profile
~/.profile
I do get
"export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home"
saved to ~/.profile, and I can check this using /usr/bin/open ~/.profile
But I do not understand why JAVA_HOME still doesn't work and I need this to install maven.
Thanks!
My ~/.bash_profile has this line in it, and it's been working fine.
export JAVA_HOME=$(/usr/libexec/java_home)
This line basically says "run the program named /usr/libexec/java_home and export its output as a variable named JAVA_HOME."
I suggest opening your .profile or .bash_profile in a text editor rather than using echo statements to append new lines to it. That way you can see everything that's in the file and make sure other old lines in the file aren't causing you issues.
After you make a change to .bash_profile, make sure you open a new terminal window before testing it.
You can check the value of any environment variable (including JAVA_HOME) by simply echo'ing its value:
echo $JAVA_HOME
In my case the output of that echo command is:
/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
Probably you misunderstood things. JAVA_HOME is not a command, it's an environment variable. You can't call JAVA_HOME in your terminal since - in fact - there is no such command, what your error message says.
You can see this variable's value by:
echo $JAVA_HOME
If it is set and points to a proper location then it's fine. Some tools that expect this variable to be set (e.g. Maven or Java IDEs) will work well.

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

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
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.
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!
add the path of the missing libraries in the file /etc/ld.so.conf
execute the following command: ldconfig
this way, you'll add the new libraries to the default ones.
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.

Categories